Skip to content

Commit 026e7ce

Browse files
committed
Always pickle the position of DefTrees
A symbol is created before the corresponding tree is unpickled, so we cannot rely on initialPos to set the symbol position. Instead, we always pickle the position of definitions. In practice, this means that we now always pickle the position of all `TypeDef` and `Bind` (the other `DefTree`s are all `WithLazyField` and thus already had their positions pickled).
1 parent 5fdd40b commit 026e7ce

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,21 @@ class PositionPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Option[Addr
4141
lastPos = pos
4242
}
4343

44-
/** True if x's position cannot be reconstructed automatically from its initialPos
44+
/** True if x's position shouldn't be reconstructed automatically from its initialPos
4545
*/
4646
def alwaysNeedsPos(x: Positioned) = x match {
47-
case _: WithLazyField[_] // initialPos is inaccurate for trees with lazy field
48-
| _: Trees.PackageDef[_] => true // package defs might be split into several Tasty files
47+
case
48+
// initialPos is inaccurate for trees with lazy field
49+
_: WithLazyField[_]
50+
51+
// A symbol is created before the corresponding tree is unpickled,
52+
// and its position cannot be changed afterwards.
53+
// so we cannot use the tree initialPos to set the symbol position.
54+
// Instead, we always pickle the position of definitions.
55+
| _: Trees.DefTree[_]
56+
57+
// package defs might be split into several Tasty files
58+
| _: Trees.PackageDef[_] => true
4959
case _ => false
5060
}
5161

0 commit comments

Comments
 (0)