Skip to content

Commit 7f17a05

Browse files
Merge pull request #11629 from dotty-staging/fix-11628
Allow eta expansion during inlining
2 parents dbf8646 + dffd2d4 commit 7f17a05

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ object EtaExpansion extends LiftImpure {
223223
*/
224224
def etaExpand(tree: Tree, mt: MethodType, xarity: Int)(using Context): untpd.Tree = {
225225
import untpd._
226-
assert(!ctx.isAfterTyper)
226+
assert(!ctx.isAfterTyper || (ctx.phase eq ctx.base.inliningPhase), ctx.phase)
227227
val defs = new mutable.ListBuffer[tpd.Tree]
228228
val lifted: Tree = TypedSplice(liftApp(defs, tree))
229229
val isLastApplication = mt.resultType match {

tests/pos/i11628/macros.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// assume that this conversion utility is defined in Scala 2
2+
class Scala2Conversion[T, V](val f: T => V)
3+
object Scala2Conversion{
4+
implicit def create[T, V](implicit f: T => V): Scala2Conversion[T, V] = new Scala2Conversion(f)
5+
}
6+
7+
// assume this utility in Scala 3, to summon a conversion within a macro
8+
import quoted._
9+
def summonConversionImpl(using qctx: Quotes): Expr[Any] = {
10+
import qctx.reflect._
11+
12+
// hardcoded in this example to look for String to Int
13+
val conversionTpe = TypeRepr.of[Scala2Conversion[String, Int]]
14+
15+
Implicits.search(conversionTpe) match {
16+
case iss: ImplicitSearchSuccess =>
17+
iss.tree.asExpr
18+
case isf: ImplicitSearchFailure =>
19+
report.error(s"can't find conversion")
20+
'{???}
21+
}
22+
}
23+
24+
inline def summonConversion() = ${summonConversionImpl}

tests/pos/i11628/main.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
implicit def s2i(x: String): Int = x.toInt
2+
3+
def main() = {
4+
summonConversion()
5+
}

0 commit comments

Comments
 (0)