Skip to content

Commit 8eea8d8

Browse files
authored
Merge pull request #9491 from dotty-staging/fix-#9484
Fix #9484: Use new macro classloader to process suspended units
2 parents 698de8d + 081e019 commit 8eea8d8

File tree

8 files changed

+46
-2
lines changed

8 files changed

+46
-2
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Driver {
3737
val run = compiler.newRun
3838
run.compile(fileNames)
3939

40-
def finish(run: Run): Unit =
40+
def finish(run: Run)(using Context): Unit =
4141
run.printSummary()
4242
if !ctx.reporter.errorsReported && run.suspendedUnits.nonEmpty then
4343
val suspendedUnits = run.suspendedUnits.toList
@@ -46,7 +46,7 @@ class Driver {
4646
val run1 = compiler.newRun
4747
for unit <- suspendedUnits do unit.suspended = false
4848
run1.compileUnits(suspendedUnits)
49-
finish(run1)
49+
finish(run1)(using MacroClassLoader.init(ctx.fresh))
5050

5151
finish(run)
5252
catch

tests/pos-macros/i9484/C.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted._
2+
3+
object C {
4+
inline def m: Any = ${ mExpr }
5+
def mExpr(using qctx: QuoteContext): Expr[Any] = Expr(1)
6+
}

tests/pos-macros/i9484/L.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
3+
object L {
4+
val m = C.m
5+
}
6+
7+
class LC

tests/pos-macros/i9484/Q.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted._
2+
3+
object Q {
4+
inline def f(): Any = ${ fExpr }
5+
def fExpr(using QuoteContext): Expr[Any] = { new LC; Expr(1) }
6+
}

tests/pos-macros/i9484/Test.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test extends App {
2+
Q.f()
3+
}

tests/pos-macros/i9484b/C.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted._
2+
3+
object C {
4+
inline def m: Any = ${ mExpr }
5+
def mExpr(using qctx: QuoteContext): Expr[Any] = '{ () }
6+
}

tests/pos-macros/i9484b/Q.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.quoted._
2+
3+
object Q {
4+
inline def f(inline f: Any): Any = ${ Q2.fExpr('f) }
5+
}
6+
7+
object Q2 {
8+
val m = C.m
9+
def fExpr(f: Expr[Any])(using QuoteContext): Expr[Any] = '{ () }
10+
}

tests/pos-macros/i9484b/Test.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class TopLevelClass {
2+
Q.f(1)
3+
}
4+
5+
val a = 1
6+
val b = Q.f(a)

0 commit comments

Comments
 (0)