Skip to content

Allow eta expansion during inlining #11629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ object EtaExpansion extends LiftImpure {
*/
def etaExpand(tree: Tree, mt: MethodType, xarity: Int)(using Context): untpd.Tree = {
import untpd._
assert(!ctx.isAfterTyper)
assert(!ctx.isAfterTyper || (ctx.phase eq ctx.base.inliningPhase), ctx.phase)
val defs = new mutable.ListBuffer[tpd.Tree]
val lifted: Tree = TypedSplice(liftApp(defs, tree))
val isLastApplication = mt.resultType match {
Expand Down
24 changes: 24 additions & 0 deletions tests/pos/i11628/macros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// assume that this conversion utility is defined in Scala 2
class Scala2Conversion[T, V](val f: T => V)
object Scala2Conversion{
implicit def create[T, V](implicit f: T => V): Scala2Conversion[T, V] = new Scala2Conversion(f)
}

// assume this utility in Scala 3, to summon a conversion within a macro
import quoted._
def summonConversionImpl(using qctx: Quotes): Expr[Any] = {
import qctx.reflect._

// hardcoded in this example to look for String to Int
val conversionTpe = TypeRepr.of[Scala2Conversion[String, Int]]

Implicits.search(conversionTpe) match {
case iss: ImplicitSearchSuccess =>
iss.tree.asExpr
case isf: ImplicitSearchFailure =>
report.error(s"can't find conversion")
'{???}
}
}

inline def summonConversion() = ${summonConversionImpl}
5 changes: 5 additions & 0 deletions tests/pos/i11628/main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
implicit def s2i(x: String): Int = x.toInt

def main() = {
summonConversion()
}