@@ -18,6 +18,8 @@ import tpd.tpes
1818import Variances .alwaysInvariant
1919import config .{Config , Feature }
2020import config .Printers .typr
21+ import parsing .JavaParsers .JavaParser
22+ import parsing .Parsers .Parser
2123import Annotations ._
2224import Inferencing ._
2325import transform .ValueClasses ._
@@ -708,15 +710,44 @@ class Namer { typer: Typer =>
708710 ctxWithStats
709711 }
710712
711- /** Index symbols in `tree` while asserting the `lateCompile` flag.
712- * This will cause any old top-level symbol with the same fully qualified
713- * name as a newly created symbol to be replaced.
713+ /** Parse the source and index symbols in the compilation unit's untpdTree
714+ * while asserting the `lateCompile` flag. This will cause any old
715+ * top-level symbol with the same fully qualified name as a newly created
716+ * symbol to be replaced.
717+ *
718+ * Will call the callback with an implementation of type checking
719+ * That will set the tpdTree and root tree for the compilation unit.
714720 */
715- def lateEnter (tree : Tree )(using Context ): Context = {
716- val saved = lateCompile
717- lateCompile = true
718- try index(tree :: Nil ) finally lateCompile = saved
719- }
721+ def lateEnterUnit (typeCheckCB : (() => Unit ) => Unit )(using Context ) =
722+ val unit = ctx.compilationUnit
723+
724+ /** Index symbols in unit.untpdTree with lateCompile flag = true */
725+ def lateEnter ()(using Context ): Context =
726+ val saved = lateCompile
727+ lateCompile = true
728+ try index(unit.untpdTree :: Nil ) finally lateCompile = saved
729+
730+ /** Set the tpdTree and root tree of the compilation unit */
731+ def lateTypeCheck ()(using Context ) =
732+ unit.tpdTree = typer.typedExpr(unit.untpdTree)
733+ val phase = new transform.SetRootTree ()
734+ phase.run
735+
736+ unit.untpdTree =
737+ if (unit.isJava) new JavaParser (unit.source).parse()
738+ else new Parser (unit.source).parse()
739+
740+ atPhase(Phases .typerPhase) {
741+ inContext(PrepareInlineable .initContext(ctx)) {
742+ // inline body annotations are set in namer, capturing the current context
743+ // we need to prepare the context for inlining.
744+ lateEnter()
745+ typeCheckCB { () =>
746+ lateTypeCheck()
747+ }
748+ }
749+ }
750+ end lateEnterUnit
720751
721752 /** The type bound on wildcard imports of an import list, with special values
722753 * Nothing if no wildcard imports of this kind exist
0 commit comments