@@ -742,6 +742,8 @@ class TreeUnpickler(reader: TastyReader,
742
742
}
743
743
744
744
private def readNewDef ()(implicit ctx : Context ): Tree = {
745
+ val sctx = sourceChangeContext
746
+ if (sctx `ne` ctx) return readNewDef()(sctx)
745
747
val start = currentAddr
746
748
val sym = symAtAddr(start)
747
749
val tag = readByte()
@@ -867,6 +869,7 @@ class TreeUnpickler(reader: TastyReader,
867
869
868
870
private def readTemplate (implicit ctx : Context ): Template = {
869
871
val start = currentAddr
872
+ assert(sourcePathAt(start).isEmpty)
870
873
val cls = ctx.owner.asClass
871
874
val assumedSelfType =
872
875
if (cls.is(Module ) && cls.owner.isClass) TermRef (cls.owner.thisType, cls.name.sourceModuleName)
@@ -952,6 +955,7 @@ class TreeUnpickler(reader: TastyReader,
952
955
953
956
def readImport ()(implicit ctx : Context ): Tree = {
954
957
val start = currentAddr
958
+ assert(sourcePathAt(start).isEmpty)
955
959
readByte()
956
960
readEnd()
957
961
val expr = readTerm()
@@ -961,6 +965,7 @@ class TreeUnpickler(reader: TastyReader,
961
965
def readSelectors ()(implicit ctx : Context ): List [untpd.Tree ] = nextByte match {
962
966
case IMPORTED =>
963
967
val start = currentAddr
968
+ assert(sourcePathAt(start).isEmpty)
964
969
readByte()
965
970
val from = setPos(start, untpd.Ident (readName()))
966
971
nextByte match {
@@ -995,6 +1000,8 @@ class TreeUnpickler(reader: TastyReader,
995
1000
// ------ Reading trees -----------------------------------------------------
996
1001
997
1002
def readTerm ()(implicit ctx : Context ): Tree = { // TODO: rename to readTree
1003
+ val sctx = sourceChangeContext
1004
+ if (sctx `ne` ctx) return readTerm()(sctx)
998
1005
val start = currentAddr
999
1006
val tag = readByte()
1000
1007
pickling.println(s " reading term ${astTagToString(tag)} at $start" )
@@ -1236,6 +1243,8 @@ class TreeUnpickler(reader: TastyReader,
1236
1243
}
1237
1244
1238
1245
def readCase ()(implicit ctx : Context ): CaseDef = {
1246
+ val sctx = sourceChangeContext
1247
+ if (sctx `ne` ctx) return readCase()(sctx)
1239
1248
val start = currentAddr
1240
1249
assert(readByte() == CASEDEF )
1241
1250
val end = readEnd()
@@ -1284,6 +1293,25 @@ class TreeUnpickler(reader: TastyReader,
1284
1293
}
1285
1294
} else NoPosition
1286
1295
1296
+ /** Pickled source path at `addr`. */
1297
+ def sourcePathAt (addr : Addr )(implicit ctx : Context ): String =
1298
+ if (ctx.mode.is(Mode .ReadPositions )) {
1299
+ posUnpicklerOpt match {
1300
+ case Some (posUnpickler) =>
1301
+ posUnpickler.sourcePathAt(addr)
1302
+ case _ =>
1303
+ " "
1304
+ }
1305
+ } else " "
1306
+
1307
+ /** If currentAddr carries a source path, the current context with
1308
+ * the source of that path, otherwise the current context itself.
1309
+ */
1310
+ def sourceChangeContext (implicit ctx : Context ): Context = {
1311
+ val path = sourcePathAt(currentAddr)
1312
+ if (path.nonEmpty) ctx.withSource(ctx.getSource(path)) else ctx
1313
+ }
1314
+
1287
1315
/** Coordinate for the symbol at `addr`. */
1288
1316
def coordAt (addr : Addr )(implicit ctx : Context ): Coord = {
1289
1317
val pos = posAt(addr)
0 commit comments