Skip to content

Commit 31e0629

Browse files
authored
Merge pull request #4112 from dotty-staging/fix/tasty-root-pos
Correct the position of root symbols unpickled from TASTY
2 parents 222516a + d76e857 commit 31e0629

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,24 @@ object Symbols {
409409
* @param coord The coordinates of the symbol (a position or an index)
410410
* @param id A unique identifier of the symbol (unique per ContextBase)
411411
*/
412-
class Symbol private[Symbols] (val coord: Coord, val id: Int) extends Designator with ParamInfo with printing.Showable {
412+
class Symbol private[Symbols] (private[this] var myCoord: Coord, val id: Int) extends Designator with ParamInfo with printing.Showable {
413413

414414
type ThisName <: Name
415415

416416
//assert(id != 723)
417417

418+
def coord: Coord = myCoord
419+
/** Set the coordinate of this class, this is only useful when the coordinate is
420+
* not known at symbol creation. This is the case for root symbols
421+
* unpickled from TASTY.
422+
*
423+
* @pre coord == NoCoord
424+
*/
425+
private[core] def coord_=(c: Coord) = {
426+
assert(myCoord == NoCoord)
427+
myCoord = c
428+
}
429+
418430
/** The last denotation of this symbol */
419431
private[this] var lastDenot: SymDenotation = _
420432
private[this] var checkedPeriod: Period = Nowhere
@@ -628,7 +640,7 @@ object Symbols {
628640

629641
/** If this is either:
630642
* - a top-level class and `-Yretain-trees` is set
631-
* - a top-level class loaded from TASTY and `-tasty` or `-Xlink` is set
643+
* - a top-level class loaded from TASTY and `-tasty` or `-Xlink` is set
632644
* then return the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
633645
* This will force the info of the class.
634646
*/

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,12 @@ class TreeUnpickler(reader: TastyReader,
492492
val flags = normalizeFlags(tag, givenFlags, name, isAbsType, rhsIsEmpty)
493493
def adjustIfModule(completer: LazyType) =
494494
if (flags is Module) ctx.adjustModuleCompleter(completer, name) else completer
495+
val coord = coordAt(start)
495496
val sym =
496497
roots.find(root => (root.owner eq ctx.owner) && root.name == name) match {
497498
case Some(rootd) =>
498499
pickling.println(i"overwriting ${rootd.symbol} # ${rootd.hashCode}")
500+
rootd.symbol.coord = coord
499501
rootd.info = adjustIfModule(
500502
new Completer(ctx.owner, subReader(start, end)) with SymbolLoaders.SecondCompleter)
501503
rootd.flags = flags &~ Touched // allow one more completion
@@ -505,8 +507,6 @@ class TreeUnpickler(reader: TastyReader,
505507
case _ =>
506508
val completer = adjustIfModule(new Completer(ctx.owner, subReader(start, end)))
507509

508-
val coord = coordAt(start)
509-
510510
if (isClass)
511511
ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord)
512512
else

0 commit comments

Comments
 (0)