diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index 2fe62cbf0ffa..32849de6f560 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -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 { diff --git a/tests/pos/i11628/macros.scala b/tests/pos/i11628/macros.scala new file mode 100644 index 000000000000..cc7b6aeec902 --- /dev/null +++ b/tests/pos/i11628/macros.scala @@ -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} diff --git a/tests/pos/i11628/main.scala b/tests/pos/i11628/main.scala new file mode 100644 index 000000000000..8a4bf3889581 --- /dev/null +++ b/tests/pos/i11628/main.scala @@ -0,0 +1,5 @@ +implicit def s2i(x: String): Int = x.toInt + +def main() = { + summonConversion() +} \ No newline at end of file