Skip to content

Commit 301178d

Browse files
oderskynicolasstucki
authored andcommitted
Improve pickling of holes
- Avoid using a mismatched sourcefile/span compbination for a hole filling - This can be achieved by always pickling the position of holes.
1 parent badebc6 commit 301178d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ class PositionPickler(pickler: TastyPickler, addrOfTree: untpd.Tree => Option[Ad
6262
| _: Trees.DefTree[_]
6363

6464
// package defs might be split into several Tasty files
65-
| _: Trees.PackageDef[_] => true
65+
| _: Trees.PackageDef[_]
66+
// holes can change source files when filled, which means
67+
// they might lose their position
68+
| _: TreePickler.Hole => true
6669
case _ => false
6770
}
6871

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,14 @@ class TreeUnpickler(reader: TastyReader,
12901290
}
12911291
// We need to make sure a hole is created with the source file of the surrounding context, even if
12921292
// it filled with contents a different source file. Otherwise nodes containing holes might end
1293-
// up without a position. TODO: It would probably more systematic to always create an Inlined argument node
1294-
// at the position of the hole.
1293+
// up without a position. PositionPickler makes sure that holes always get spans assigned,
1294+
// so we can just return the filler tree with the new source and no span here.
12951295
if (filled.source == ctx.source) filled
1296-
else filled.cloneIn(ctx.source)
1296+
else {
1297+
val filled1 = filled.cloneIn(ctx.source)
1298+
filled1.span = NoSpan
1299+
filled1
1300+
}
12971301
}
12981302

12991303
// ------ Setting positions ------------------------------------------------

0 commit comments

Comments
 (0)