Skip to content

Commit 7fe6ea4

Browse files
committed
Bring back previous typerState after suspending a compilation unit
This is to avaoid unfulfilled constraints when going through -Ycheck later.
1 parent 60e421b commit 7fe6ea4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

compiler/src/dotty/tools/dotc/core/Phases.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ object Phases {
375375
val doCheckJava = skipIfJava && !isAfterLastJavaPhase
376376
for unit <- units do ctx.profiler.onUnit(this, unit):
377377
given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
378+
val previousTyperState = unitCtx.typerState.snapshot()
378379
if ctx.run.enterUnit(unit) then
379380
try
380381
if doCheckJava && unit.typedAsJava then
@@ -384,6 +385,7 @@ object Phases {
384385
buf += unitCtx.compilationUnit
385386
catch
386387
case _: CompilationUnit.SuspendException => // this unit will be run again in `Run#compileSuspendedUnits`
388+
unitCtx.typerState.resetTo(previousTyperState)
387389
case ex: Throwable if !ctx.run.enrichedErrorMessage =>
388390
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
389391
throw ex

tests/pos/i21176-b/Macro.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted.*
2+
3+
class Macro:
4+
inline def nameTuple[NameTuple_T]: (String, List[NameTuple_T]) = Macro.tuple[NameTuple_T](Macro.named)
5+
6+
object Macro:
7+
def namedMacro(using q: Quotes): Expr[String] = Expr("test")
8+
inline def named: String = ${Macro.namedMacro}
9+
def tuple[Tuple_T](name: String): (String, List[Tuple_T]) = (name, List.empty[Tuple_T])

tests/pos/i21176-b/Main.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Test extends Macro:
2+
val abc = nameTuple[Int]

0 commit comments

Comments
 (0)