Skip to content

Commit 469c980

Browse files
authored
Fix i19859 (#19860)
Fixes #19859.
2 parents 02cc983 + 7aca3c4 commit 469c980

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,19 +405,21 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
405405
pickleType(tp)
406406
}
407407
case This(qual) =>
408+
// This may be needed when pickling a `This` inside a capture set. See #19662 and #19859.
409+
// In this case, we pickle the tree as null.asInstanceOf[tree.tpe].
410+
// Since the pickled tree is not the same as the input, special handling is needed
411+
// in the tree printer when testing the pickler. See [[PlainPrinter#homogenize]].
412+
inline def pickleCapturedThis =
413+
pickleTree(Literal(Constant(null)).cast(tree.tpe).withSpan(tree.span))
408414
if (qual.isEmpty)
409415
if tree.tpe.isSingleton then pickleType(tree.tpe)
410-
else
411-
// This may happen when pickling a `This` inside a capture set. See #19662.
412-
// In this case, we pickle the tree as null.asInstanceOf[tree.tpe].
413-
// Since the pickled tree is not the same as the input, special handling is needed
414-
// in the tree printer when testing the pickler. See [[PlainPrinter#homogenize]].
415-
pickleTree(Literal(Constant(null)).cast(tree.tpe).withSpan(tree.span))
416-
else {
417-
writeByte(QUALTHIS)
418-
val ThisType(tref) = tree.tpe: @unchecked
419-
pickleTree(qual.withType(tref))
420-
}
416+
else pickleCapturedThis
417+
else
418+
tree.tpe match
419+
case ThisType(tref) =>
420+
writeByte(QUALTHIS)
421+
pickleTree(qual.withType(tref))
422+
case _ => pickleCapturedThis
421423
case Select(qual, name) =>
422424
name match {
423425
case OuterSelectName(_, levels) =>

0 commit comments

Comments
 (0)