@@ -18,6 +18,8 @@ import tpd.tpes
18
18
import Variances .alwaysInvariant
19
19
import config .{Config , Feature }
20
20
import config .Printers .typr
21
+ import parsing .JavaParsers .JavaParser
22
+ import parsing .Parsers .Parser
21
23
import Annotations ._
22
24
import Inferencing ._
23
25
import transform .ValueClasses ._
@@ -708,15 +710,43 @@ class Namer { typer: Typer =>
708
710
ctxWithStats
709
711
}
710
712
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
+ /** Index symbols in the compilation unit's untpdTree while asserting the
714
+ * `lateCompile` flag. This will cause any old top-level symbol with the
715
+ * same fully qualified name as a newly created symbol to be replaced.
716
+ *
717
+ * Will call the callback with an implementation of type checking
718
+ * That will set the tpdTree and root tree for the compilation unit.
714
719
*/
715
- def lateEnter (tree : Tree )(using Context ): Context = {
716
- val saved = lateCompile
717
- lateCompile = true
718
- try index(tree :: Nil ) finally lateCompile = saved
719
- }
720
+ def lateEnterUnit (typeCheckCB : (() => Unit ) => Unit )(using Context ) =
721
+ val unit = ctx.compilationUnit
722
+
723
+ /** Index symbols in unit.untpdTree with lateCompile flag = true */
724
+ def lateEnter ()(using Context ): Context = {
725
+ val saved = lateCompile
726
+ lateCompile = true
727
+ try index(unit.untpdTree :: Nil ) finally lateCompile = saved
728
+ }
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
+ inContext(PrepareInlineable .initContext(ctx)) {
741
+ // inline body annotations are set in namer, capturing the current context
742
+ // we need to prepare the context for inlining.
743
+ lateEnter()
744
+ typeCheckCB { () =>
745
+ atPhase(Phases .typerPhase) {
746
+ lateTypeCheck()
747
+ }
748
+ }
749
+ }
720
750
721
751
/** The type bound on wildcard imports of an import list, with special values
722
752
* Nothing if no wildcard imports of this kind exist
0 commit comments