Skip to content

Commit dbf2dd6

Browse files
bishaboshaolsdavis
authored andcommitted
fix scala#13994: initialise inline ctx in lateEnter
1 parent 626f17e commit dbf2dd6

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Types._
99
import Scopes._
1010
import Names.Name
1111
import Denotations.Denotation
12-
import typer.Typer
12+
import typer.{Typer, PrepareInlineable}
1313
import typer.ImportInfo._
1414
import Decorators._
1515
import io.{AbstractFile, PlainFile, VirtualFile}
@@ -303,17 +303,30 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
303303
.withRootImports
304304

305305
def process()(using Context) = {
306-
unit.untpdTree =
306+
307+
def parseSource()(using Context) =
307308
if (unit.isJava) new JavaParser(unit.source).parse()
308309
else new Parser(unit.source).parse()
309-
ctx.typer.lateEnter(unit.untpdTree)
310-
def processUnit() = {
311-
unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
312-
val phase = new transform.SetRootTree()
313-
phase.run
314-
}
315-
if (typeCheck)
316-
if (compiling) finalizeActions += (() => processUnit()) else processUnit()
310+
311+
def enterTrees()(using Context) =
312+
ctx.typer.lateEnter(unit.untpdTree)
313+
def typeCheckUnit()(using Context) =
314+
unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
315+
val phase = new transform.SetRootTree()
316+
phase.run
317+
if typeCheck then
318+
val typerCtx: Context =
319+
// typer phase allows implicits to be searched
320+
ctx.withPhase(Phases.typerPhase)
321+
if compiling then finalizeActions += (() => typeCheckUnit()(using typerCtx))
322+
else typeCheckUnit()(using typerCtx)
323+
324+
unit.untpdTree = parseSource()
325+
val namerCtx =
326+
// inline body annotations are set in namer, capturing the current context
327+
// we need to prepare the context for inlining.
328+
if unit.isJava then ctx else PrepareInlineable.initContext(ctx)
329+
enterTrees()(using namerCtx)
317330
}
318331
process()(using unitCtx)
319332
}

0 commit comments

Comments
 (0)