@@ -19,7 +19,7 @@ import scala.annotation.internal.sharable
1919import scala .util .control .NoStackTrace
2020import transform .MacroAnnotations
2121
22- class CompilationUnit protected (val source : SourceFile ) {
22+ class CompilationUnit protected (val source : SourceFile , val info : CompilationUnitInfo | Null ) {
2323
2424 override def toString : String = source.toString
2525
@@ -106,7 +106,7 @@ class CompilationUnit protected (val source: SourceFile) {
106106 myAssignmentSpans.nn
107107}
108108
109- @ sharable object NoCompilationUnit extends CompilationUnit (NoSource ) {
109+ @ sharable object NoCompilationUnit extends CompilationUnit (NoSource , info = null ) {
110110
111111 override def isJava : Boolean = false
112112
@@ -122,13 +122,14 @@ object CompilationUnit {
122122
123123 /** Make a compilation unit for top class `clsd` with the contents of the `unpickled` tree */
124124 def apply (clsd : ClassDenotation , unpickled : Tree , forceTrees : Boolean )(using Context ): CompilationUnit =
125- val file = clsd.symbol.associatedFile.nn
126- apply(SourceFile (file, Array .empty[Char ]), unpickled, forceTrees)
125+ val compilationUnitInfo = clsd.symbol.compilationUnitInfo.nn
126+ val file = compilationUnitInfo.associatedFile
127+ apply(SourceFile (file, Array .empty[Char ]), unpickled, forceTrees, compilationUnitInfo)
127128
128129 /** Make a compilation unit, given picked bytes and unpickled tree */
129- def apply (source : SourceFile , unpickled : Tree , forceTrees : Boolean )(using Context ): CompilationUnit = {
130+ def apply (source : SourceFile , unpickled : Tree , forceTrees : Boolean , info : CompilationUnitInfo )(using Context ): CompilationUnit = {
130131 assert(! unpickled.isEmpty, unpickled)
131- val unit1 = new CompilationUnit (source)
132+ val unit1 = new CompilationUnit (source, info )
132133 unit1.tpdTree = unpickled
133134 if (forceTrees) {
134135 val force = new Force
@@ -156,7 +157,8 @@ object CompilationUnit {
156157 NoSource
157158 }
158159 else source
159- new CompilationUnit (src)
160+ val info = if src.exists then CompilationUnitInfo (src.file) else null
161+ new CompilationUnit (src, info)
160162 }
161163
162164 /** Force the tree to be loaded */
0 commit comments