From f481cc58cc92e42501620d15418b2f8a5c5aa42a Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Thu, 20 Nov 2025 13:58:48 +0100 Subject: [PATCH] Cleanup the info of a Bind symbol in posttyper [Cherry-picked c0abb058cc0443b27b44359c509327e2ac15bc00] --- .../src/dotty/tools/dotc/transform/PostTyper.scala | 7 +++++-- tests/pos-custom-args/captures/i24456.scala | 14 ++++++++++++++ tests/pos/i24456.scala | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/pos-custom-args/captures/i24456.scala create mode 100644 tests/pos/i24456.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 29baf816da5e..62561ad2d467 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -624,8 +624,11 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => case _ => processMemberDef(super.transform(scala2LibPatch(tree))) case tree: Bind => - if tree.symbol.isType && !tree.symbol.name.is(WildcardParamName) then - Checking.checkGoodBounds(tree.symbol) + val sym = tree.symbol + if sym.isType && !sym.name.is(WildcardParamName) then + Checking.checkGoodBounds(sym) + // Cleanup retains from the info of the Bind symbol + sym.copySymDenotation(info = transformAnnotsIn(CleanupRetains()(sym.info))).installAfter(thisPhase) super.transform(tree) case tree: New if isCheckable(tree) => Checking.checkInstantiable(tree.tpe, tree.tpe, tree.srcPos) diff --git a/tests/pos-custom-args/captures/i24456.scala b/tests/pos-custom-args/captures/i24456.scala new file mode 100644 index 000000000000..e70145325113 --- /dev/null +++ b/tests/pos-custom-args/captures/i24456.scala @@ -0,0 +1,14 @@ +// Similar to i24207 + +class Generator: + private def generateTable(table: Table) = + val (ownRelations, unusedTerm) = calculateOwnRelations(table) + None + + 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 \ No newline at end of file diff --git a/tests/pos/i24456.scala b/tests/pos/i24456.scala new file mode 100644 index 000000000000..e70145325113 --- /dev/null +++ b/tests/pos/i24456.scala @@ -0,0 +1,14 @@ +// Similar to i24207 + +class Generator: + private def generateTable(table: Table) = + val (ownRelations, unusedTerm) = calculateOwnRelations(table) + None + + 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 \ No newline at end of file