Skip to content

Commit 1c9d27a

Browse files
authored
Fix #24207: Cleanup the type of UnApply trees in posttyper (#24259)
Fix #24207 The pickling of `UnApply` trees uses the type of the tree, so we need to clean retains annotations from it as inferred type.
2 parents 520668f + 170f1ff commit 1c9d27a

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
523523
case UnApply(fun, implicits, patterns) =>
524524
// Reverse transform order for the same reason as in `app1` above.
525525
val patterns1 = transform(patterns)
526-
cpy.UnApply(tree)(transform(fun), transform(implicits), patterns1)
526+
val tree1 = cpy.UnApply(tree)(transform(fun), transform(implicits), patterns1)
527+
// The pickling of UnApply trees uses the tpe of the tree,
528+
// so we need to clean retains from it here
529+
tree1.withType(transformAnnotsIn(CleanupRetains()(tree1.tpe)))
527530
case tree: TypeApply =>
528531
if tree.symbol == defn.QuotedTypeModule_of then
529532
ctx.compilationUnit.needsStaging = true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import language.experimental.captureChecking
2+
3+
class Generator:
4+
private def generateTable(table: Table) =
5+
val (ownRelations, _) = calculateOwnRelations(table)
6+
ownRelations
7+
8+
private def calculateOwnRelations(table: Table) =
9+
val ownRelations = table.relations.filter(_.association.isDefined)
10+
(ownRelations, Nil)
11+
12+
case class Table(relations: Seq[TableRelation])
13+
case class TableRelation(association: Option[Association])
14+
trait Association

tests/pos/i24207.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Generator:
2+
private def generateTable(table: Table) =
3+
val (ownRelations, _) = calculateOwnRelations(table)
4+
ownRelations
5+
6+
private def calculateOwnRelations(table: Table) =
7+
val ownRelations = table.relations.filter(_.association.isDefined)
8+
(ownRelations, Nil)
9+
10+
case class Table(relations: Seq[TableRelation])
11+
case class TableRelation(association: Option[Association])
12+
trait Association

0 commit comments

Comments
 (0)