@@ -265,12 +265,21 @@ object Symbols {
265265
266266 /** The source or class file from which this class or
267267 * the class containing this symbol was generated, null if not applicable.
268- * Note that this the returned classfile might be the top-level class
268+ * Note that the returned classfile might be from the top-level class
269269 * containing this symbol instead of the directly enclosing class.
270- * Overridden in ClassSymbol
271270 */
272271 def associatedFile (using Context ): AbstractFile | Null =
273- lastDenot.topLevelClass.associatedFile
272+ val compUnitInfo = compilationUnitInfo
273+ if compUnitInfo == null then (null : AbstractFile | Null )
274+ else compUnitInfo.associatedFile
275+
276+ /** The compilation unit info (associated file, tasty versions, ...).
277+ * Note that the returned CompilationUnitInfo might be from the top-level class
278+ * containing this symbol instead of the directly enclosing class.
279+ * Overridden in ClassSymbol
280+ */
281+ def compilationUnitInfo (using Context ): CompilationUnitInfo | Null =
282+ lastDenot.topLevelClass.compilationUnitInfo
274283
275284 /** The class file from which this class was generated, null if not applicable. */
276285 final def binaryFile (using Context ): AbstractFile | Null = {
@@ -353,7 +362,7 @@ object Symbols {
353362 def paramRef (using Context ): TypeRef = denot.typeRef
354363
355364 /** Copy a symbol, overriding selective fields.
356- * Note that `coord` and `associatedFile ` will be set from the fields in `owner`, not
365+ * Note that `coord` and `compilationUnitInfo ` will be set from the fields in `owner`, not
357366 * the fields in `sym`. */
358367 def copy (using Context )(
359368 owner : Symbol = this .owner,
@@ -362,13 +371,14 @@ object Symbols {
362371 info : Type = this .info,
363372 privateWithin : Symbol = this .privateWithin,
364373 coord : Coord = NoCoord , // Can be `= owner.coord` once we bootstrap
365- associatedFile : AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap
374+ compUnitInfo : CompilationUnitInfo | Null = null // Can be `= owner.associatedFile` once we bootstrap
366375 ): Symbol = {
367376 val coord1 = if (coord == NoCoord ) owner.coord else coord
368- val associatedFile1 = if (associatedFile == null ) owner.associatedFile else associatedFile
377+ val compilationUnitInfo1 = if (compilationUnitInfo == null ) owner.compilationUnitInfo else compilationUnitInfo
378+
369379
370380 if isClass then
371- newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1 )
381+ newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, compilationUnitInfo1 )
372382 else
373383 newSymbol(owner, name, flags, info, privateWithin, coord1)
374384 }
@@ -396,7 +406,7 @@ object Symbols {
396406 type TermSymbol = Symbol { type ThisName = TermName }
397407 type TypeSymbol = Symbol { type ThisName = TypeName }
398408
399- class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile | Null , id : Int , nestingLevel : Int )
409+ class ClassSymbol private [Symbols ] (coord : Coord , val compUnitInfo : CompilationUnitInfo | Null , id : Int , nestingLevel : Int )
400410 extends Symbol (coord, id, nestingLevel) {
401411
402412 type ThisName = TypeName
@@ -456,9 +466,9 @@ object Symbols {
456466 }
457467
458468 /** The source or class file from which this class was generated, null if not applicable. */
459- override def associatedFile (using Context ): AbstractFile | Null =
460- if assocFile != null || this .is(Package ) || this .owner.is(Package ) then assocFile
461- else super .associatedFile
469+ override def compilationUnitInfo (using Context ): CompilationUnitInfo | Null =
470+ if compUnitInfo != null || this .is(Package ) || this .owner.is(Package ) then compUnitInfo
471+ else super .compilationUnitInfo
462472
463473 private var mySource : SourceFile = NoSource
464474
@@ -488,7 +498,7 @@ object Symbols {
488498 }
489499
490500 @ sharable object NoSymbol extends Symbol (NoCoord , 0 , 0 ) {
491- override def associatedFile (using Context ): AbstractFile | Null = NoSource .file
501+ override def compilationUnitInfo (using Context ): CompilationUnitInfo | Null = CompilationUnitInfo ( NoSource .file)
492502 override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation = NoDenotation
493503 }
494504
@@ -537,9 +547,9 @@ object Symbols {
537547 infoFn : ClassSymbol => Type ,
538548 privateWithin : Symbol = NoSymbol ,
539549 coord : Coord = NoCoord ,
540- assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol
550+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): ClassSymbol
541551 = {
542- val cls = new ClassSymbol (coord, assocFile , ctx.base.nextSymId, ctx.nestingLevel)
552+ val cls = new ClassSymbol (coord, compUnitInfo , ctx.base.nextSymId, ctx.nestingLevel)
543553 val denot = SymDenotation (cls, owner, name, flags, infoFn(cls), privateWithin)
544554 cls.denot = denot
545555 cls
@@ -555,11 +565,11 @@ object Symbols {
555565 selfInfo : Type = NoType ,
556566 privateWithin : Symbol = NoSymbol ,
557567 coord : Coord = NoCoord ,
558- assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol =
568+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): ClassSymbol =
559569 newClassSymbol(
560570 owner, name, flags,
561571 ClassInfo (owner.thisType, _, parents, decls, selfInfo),
562- privateWithin, coord, assocFile )
572+ privateWithin, coord, compUnitInfo )
563573
564574 /** Same as `newCompleteClassSymbol` except that `parents` can be a list of arbitrary
565575 * types which get normalized into type refs and parameter bindings.
@@ -572,15 +582,15 @@ object Symbols {
572582 selfInfo : Type = NoType ,
573583 privateWithin : Symbol = NoSymbol ,
574584 coord : Coord = NoCoord ,
575- assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol = {
585+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): ClassSymbol = {
576586 def completer = new LazyType {
577587 def complete (denot : SymDenotation )(using Context ): Unit = {
578588 val cls = denot.asClass.classSymbol
579589 val decls = newScope
580590 denot.info = ClassInfo (owner.thisType, cls, parentTypes.map(_.dealias), decls, selfInfo)
581591 }
582592 }
583- newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile )
593+ newClassSymbol(owner, name, flags, completer, privateWithin, coord, compUnitInfo )
584594 }
585595
586596 def newRefinedClassSymbol (coord : Coord = NoCoord )(using Context ): ClassSymbol =
@@ -598,15 +608,15 @@ object Symbols {
598608 infoFn : (TermSymbol , ClassSymbol ) => Type , // typically a ModuleClassCompleterWithDecls
599609 privateWithin : Symbol = NoSymbol ,
600610 coord : Coord = NoCoord ,
601- assocFile : AbstractFile | Null = null )(using Context ): TermSymbol
611+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): TermSymbol
602612 = {
603613 val base = owner.thisType
604614 val modclsFlags = clsFlags | ModuleClassCreationFlags
605615 val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags)
606616 val module = newSymbol(
607617 owner, name, modFlags | ModuleValCreationFlags , NoCompleter , privateWithin, coord)
608618 val modcls = newClassSymbol(
609- owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile )
619+ owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, compUnitInfo )
610620 module.info =
611621 if (modcls.isCompleted) TypeRef (owner.thisType, modcls)
612622 else new ModuleCompleter (modcls)
@@ -627,12 +637,12 @@ object Symbols {
627637 decls : Scope ,
628638 privateWithin : Symbol = NoSymbol ,
629639 coord : Coord = NoCoord ,
630- assocFile : AbstractFile | Null = null )(using Context ): TermSymbol =
640+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): TermSymbol =
631641 newModuleSymbol(
632642 owner, name, modFlags, clsFlags,
633643 (module, modcls) => ClassInfo (
634644 owner.thisType, modcls, parents, decls, TermRef (owner.thisType, module)),
635- privateWithin, coord, assocFile )
645+ privateWithin, coord, compUnitInfo )
636646
637647 /** Same as `newCompleteModuleSymbol` except that `parents` can be a list of arbitrary
638648 * types which get normalized into type refs and parameter bindings.
@@ -646,7 +656,7 @@ object Symbols {
646656 decls : Scope ,
647657 privateWithin : Symbol = NoSymbol ,
648658 coord : Coord = NoCoord ,
649- assocFile : AbstractFile | Null = null )(using Context ): TermSymbol = {
659+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): TermSymbol = {
650660 def completer (module : Symbol ) = new LazyType {
651661 def complete (denot : SymDenotation )(using Context ): Unit = {
652662 val cls = denot.asClass.classSymbol
@@ -657,7 +667,7 @@ object Symbols {
657667 newModuleSymbol(
658668 owner, name, modFlags, clsFlags,
659669 (module, modcls) => completer(module),
660- privateWithin, coord, assocFile )
670+ privateWithin, coord, compUnitInfo )
661671 }
662672
663673 /** Create a package symbol with associated package class
@@ -697,17 +707,17 @@ object Symbols {
697707 /** Create a stub symbol that will issue a missing reference error
698708 * when attempted to be completed.
699709 */
700- def newStubSymbol (owner : Symbol , name : Name , file : AbstractFile | Null = null )(using Context ): Symbol = {
710+ def newStubSymbol (owner : Symbol , name : Name , compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): Symbol = {
701711 def stubCompleter = new StubInfo ()
702712 val normalizedOwner = if (owner.is(ModuleVal )) owner.moduleClass else owner
703- typr.println(s " creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, file = $file " )
713+ typr.println(s " creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, compilation unit = $compUnitInfo " )
704714 typr.println(s " decls = ${normalizedOwner.unforcedDecls.toList.map(_.debugString).mkString(" \n " )}" ) // !!! DEBUG
705715 // if (base.settings.debug.value) throw new Error()
706716 val stub = name match {
707717 case name : TermName =>
708- newModuleSymbol(normalizedOwner, name, EmptyFlags , EmptyFlags , stubCompleter, assocFile = file )
718+ newModuleSymbol(normalizedOwner, name, EmptyFlags , EmptyFlags , stubCompleter, compUnitInfo = compUnitInfo )
709719 case name : TypeName =>
710- newClassSymbol(normalizedOwner, name, EmptyFlags , stubCompleter, assocFile = file )
720+ newClassSymbol(normalizedOwner, name, EmptyFlags , stubCompleter, compUnitInfo = compUnitInfo )
711721 }
712722 stub
713723 }
0 commit comments