Skip to content

Commit d09e36b

Browse files
committed
fix scala#13994: initialise inline ctx in lateEnter
1 parent 097356d commit d09e36b

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

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

Lines changed: 24 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}
@@ -34,6 +34,7 @@ import java.nio.charset.StandardCharsets
3434

3535
import scala.collection.mutable
3636
import scala.util.control.NonFatal
37+
import scala.util.chaining.*
3738
import scala.io.Codec
3839

3940
/** A compiler run. Exports various methods to compile source files */
@@ -303,17 +304,30 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
303304
.withRootImports
304305

305306
def process()(using Context) = {
306-
unit.untpdTree =
307+
308+
def parseSource()(using Context) =
307309
if (unit.isJava) new JavaParser(unit.source).parse()
308310
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()
311+
312+
def enterTrees()(using Context) =
313+
ctx.typer.lateEnter(unit.untpdTree)
314+
def typeCheckUnit()(using Context) =
315+
unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
316+
val phase = new transform.SetRootTree()
317+
phase.run
318+
if typeCheck then
319+
val typerCtx: Context =
320+
// typer phase allows implicits to be searched
321+
ctx.withPhase(Phases.typerPhase)
322+
if compiling then finalizeActions += (() => typeCheckUnit()(using typerCtx))
323+
else typeCheckUnit()(using typerCtx)
324+
325+
unit.untpdTree = parseSource()
326+
val namerCtx =
327+
// inline body annotations are set in namer, capturing the current context
328+
// we need to prepare the context for inlining.
329+
if unit.isJava then ctx else PrepareInlineable.initContext(ctx)
330+
enterTrees()(using namerCtx)
317331
}
318332
process()(using unitCtx)
319333
}

0 commit comments

Comments
 (0)