File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
compiler/src/dotty/tools/dotc/core/tasty Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -519,6 +519,8 @@ class TreePickler(pickler: TastyPickler) {
519
519
writeByte(PACKAGE )
520
520
withLength { pickleType(pid.tpe); pickleStats(stats) }
521
521
case tree : TypeTree =>
522
+ // See the comment in TreeUnpickler#readTpt to know why this is required
523
+ assert(tree.pos.exists, " Cannot pickle $tree because it doesn't have a position." )
522
524
pickleType(tree.tpe)
523
525
case SingletonTypeTree (ref) =>
524
526
writeByte(SINGLETONtpt )
Original file line number Diff line number Diff line change @@ -1055,7 +1055,30 @@ class TreeUnpickler(reader: TastyReader,
1055
1055
else {
1056
1056
val start = currentAddr
1057
1057
val tp = readType()
1058
- if (tp.exists) setPos(start, TypeTree (tp)) else EmptyTree
1058
+ if (tp.exists) {
1059
+ val tree = TypeTree (tp)
1060
+ var addr = start
1061
+ var pos = posAt(addr)
1062
+ // This is subtle: when a TypeTree is pickled as just a type, we don't know if SHARED
1063
+ // means that just the type is shared, or the full TypeTree is shared. This matter
1064
+ // when trying to set the position of a TypeTree:
1065
+ // - If just the type is shared, then the SHARED node will have its
1066
+ // own pickled position for the TypeTree.
1067
+ // - If the full TypeTree is shared then the SHARED node will have no
1068
+ // position on its own, and we need to look at the position at the
1069
+ // referenced address.
1070
+ //
1071
+ // To distinguish between the two, we assume that pickled TypeTrees always have
1072
+ // a pickled position, this is enforced in TreePickler#pickleTree
1073
+ while (pos == NoPosition && bytes(index(addr)) == SHARED ) {
1074
+ val sharedFork = fork
1075
+ sharedFork.reader.readByte()
1076
+ addr = sharedFork.reader.readAddr()
1077
+ pos = posAt(addr)
1078
+ }
1079
+ if (pos.exists) tree.setPosUnchecked(pos)
1080
+ tree
1081
+ } else EmptyTree
1059
1082
}
1060
1083
1061
1084
def readCases (end : Addr )(implicit ctx : Context ): List [CaseDef ] =
You can’t perform that action at this time.
0 commit comments