From 170f1ffc91955615fb8005f59df3812711f88354 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Sun, 26 Oct 2025 13:12:48 +0100 Subject: [PATCH] Cleanup the type of UnApply trees in posttyper --- .../src/dotty/tools/dotc/transform/PostTyper.scala | 5 ++++- tests/pos-custom-args/captures/i24207.scala | 14 ++++++++++++++ tests/pos/i24207.scala | 12 ++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/pos-custom-args/captures/i24207.scala create mode 100644 tests/pos/i24207.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index d1824abf9c0f..29baf816da5e 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -523,7 +523,10 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => case UnApply(fun, implicits, patterns) => // Reverse transform order for the same reason as in `app1` above. val patterns1 = transform(patterns) - cpy.UnApply(tree)(transform(fun), transform(implicits), patterns1) + val tree1 = cpy.UnApply(tree)(transform(fun), transform(implicits), patterns1) + // The pickling of UnApply trees uses the tpe of the tree, + // so we need to clean retains from it here + tree1.withType(transformAnnotsIn(CleanupRetains()(tree1.tpe))) case tree: TypeApply => if tree.symbol == defn.QuotedTypeModule_of then ctx.compilationUnit.needsStaging = true diff --git a/tests/pos-custom-args/captures/i24207.scala b/tests/pos-custom-args/captures/i24207.scala new file mode 100644 index 000000000000..075b42315a3c --- /dev/null +++ b/tests/pos-custom-args/captures/i24207.scala @@ -0,0 +1,14 @@ +import language.experimental.captureChecking + +class Generator: + private def generateTable(table: Table) = + val (ownRelations, _) = calculateOwnRelations(table) + ownRelations + + private def calculateOwnRelations(table: Table) = + val ownRelations = table.relations.filter(_.association.isDefined) + (ownRelations, Nil) + +case class Table(relations: Seq[TableRelation]) +case class TableRelation(association: Option[Association]) +trait Association diff --git a/tests/pos/i24207.scala b/tests/pos/i24207.scala new file mode 100644 index 000000000000..557b6f982f2b --- /dev/null +++ b/tests/pos/i24207.scala @@ -0,0 +1,12 @@ +class Generator: + private def generateTable(table: Table) = + val (ownRelations, _) = calculateOwnRelations(table) + ownRelations + + private def calculateOwnRelations(table: Table) = + val ownRelations = table.relations.filter(_.association.isDefined) + (ownRelations, Nil) + +case class Table(relations: Seq[TableRelation]) +case class TableRelation(association: Option[Association]) +trait Association