From a10c7f7be1a0d2ecacaf4a0252f34ca72be35b37 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 29 Sep 2025 01:02:45 +0200 Subject: [PATCH 1/3] Mark the type of lifted definitions as inferred --- .../src/dotty/tools/dotc/typer/EtaExpansion.scala | 4 +++- tests/pos-custom-args/captures/i24101/S1.scala | 4 ++++ tests/pos-custom-args/captures/i24101/S2.scala | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/pos-custom-args/captures/i24101/S1.scala create mode 100644 tests/pos-custom-args/captures/i24101/S2.scala diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index 317cce45995e..3fb02026f7aa 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -37,7 +37,9 @@ abstract class Lifter { protected def liftedFlags: FlagSet = EmptyFlags /** The tree of a lifted definition */ - protected def liftedDef(sym: TermSymbol, rhs: Tree)(using Context): MemberDef = ValDef(sym, rhs) + protected def liftedDef(sym: TermSymbol, rhs: Tree)(using Context): MemberDef = + // Mark the type of lifted definitions as inferred + ValDef(sym, rhs, inferred = true) private def lift(defs: mutable.ListBuffer[Tree], expr: Tree, prefix: TermName = EmptyTermName)(using Context): Tree = if (noLift(expr)) expr diff --git a/tests/pos-custom-args/captures/i24101/S1.scala b/tests/pos-custom-args/captures/i24101/S1.scala new file mode 100644 index 000000000000..bd0b2e54674e --- /dev/null +++ b/tests/pos-custom-args/captures/i24101/S1.scala @@ -0,0 +1,4 @@ +import language.experimental.captureChecking + +trait MyMap[K, V]: + def filterNot(pred: ((K, V)) => Boolean): MyMap[K, V]^{this, pred} = ??? diff --git a/tests/pos-custom-args/captures/i24101/S2.scala b/tests/pos-custom-args/captures/i24101/S2.scala new file mode 100644 index 000000000000..91050e6e33ca --- /dev/null +++ b/tests/pos-custom-args/captures/i24101/S2.scala @@ -0,0 +1,14 @@ +trait AttributeValue + +case class CompletedSpan( + name: String, // remove to make it compile + attributes: MyMap[String, AttributeValue], +){ + lazy val allAttributes: MyMap[String, AttributeValue] = attributes + var allAttributes2: MyMap[String, AttributeValue] = attributes +} + +def Test = + val span: CompletedSpan = ??? + span.copy(attributes = span.allAttributes.filterNot { _ => false }) + span.copy(attributes = span.allAttributes2.filterNot { _ => false }) \ No newline at end of file From 715811bee5243038a335da44087a5c675f90c221 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 29 Sep 2025 19:45:09 +0200 Subject: [PATCH 2/3] Don't make overriding types declared when cc is not enabled --- .../tools/dotc/transform/PostTyper.scala | 4 ++- .../S1.scala | 3 ++ .../clear-retains-for-inferred-types/S2.scala | 36 +++++++++++++++++++ .../pos-custom-args/captures/i24101/S2.scala | 14 -------- 4 files changed, 42 insertions(+), 15 deletions(-) rename tests/pos-custom-args/captures/{i24101 => clear-retains-for-inferred-types}/S1.scala (67%) create mode 100644 tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala delete mode 100644 tests/pos-custom-args/captures/i24101/S2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 128655debc2e..d1824abf9c0f 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -371,11 +371,13 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => * clean retains annotations from such types. But for an overriding symbol the * retains annotations come from the explicitly declared parent types, so should * be kept. + * TODO: If the overriden type is an InferredType, we should probably clean retains + * from both types as well. */ private def makeOverrideTypeDeclared(symbol: Symbol, tpt: Tree)(using Context): Tree = tpt match case tpt: InferredTypeTree - if symbol.allOverriddenSymbols.hasNext => + if Feature.ccEnabled && symbol.allOverriddenSymbols.hasNext => TypeTree(tpt.tpe, inferred = false).withSpan(tpt.span).withAttachmentsFrom(tpt) case _ => tpt diff --git a/tests/pos-custom-args/captures/i24101/S1.scala b/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S1.scala similarity index 67% rename from tests/pos-custom-args/captures/i24101/S1.scala rename to tests/pos-custom-args/captures/clear-retains-for-inferred-types/S1.scala index bd0b2e54674e..c029ca000285 100644 --- a/tests/pos-custom-args/captures/i24101/S1.scala +++ b/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S1.scala @@ -2,3 +2,6 @@ import language.experimental.captureChecking trait MyMap[K, V]: def filterNot(pred: ((K, V)) => Boolean): MyMap[K, V]^{this, pred} = ??? + +trait MySeq[+T]: + def map[U](f: T => U): MySeq[U]^{this, f} = ??? diff --git a/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala b/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala new file mode 100644 index 000000000000..8f7d6a26698f --- /dev/null +++ b/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala @@ -0,0 +1,36 @@ +import language.experimental.{captureChecking => _} + +// i24101 + +trait AttributeValue + +case class CompletedSpan( + name: String, // remove to make it compile + attributes: MyMap[String, AttributeValue], +){ + lazy val allAttributes: MyMap[String, AttributeValue] = attributes + var allAttributes2: MyMap[String, AttributeValue] = attributes +} + +def Test = + val span: CompletedSpan = ??? + span.copy(attributes = span.allAttributes.filterNot { _ => false }) + span.copy(attributes = span.allAttributes2.filterNot { _ => false }) + +// i24100 + +trait Type + +type ColumnDef = ColumnDef_[Type] +case class ColumnDef_[+T](comments: String) + +type TableDef = TableDef_[ColumnDef] +case class TableDef_[+C <: ColumnDef_[?]](cols: MySeq[C]) + +abstract class DdlGenerator: + // The result type is inferred here + def columnComments(t: TableDef) = t.cols.map(_ => "") + +class CassandraDdlGenerator() extends DdlGenerator: + // The result type should be inferred here as well + override def columnComments(t: TableDef) = ??? \ No newline at end of file diff --git a/tests/pos-custom-args/captures/i24101/S2.scala b/tests/pos-custom-args/captures/i24101/S2.scala deleted file mode 100644 index 91050e6e33ca..000000000000 --- a/tests/pos-custom-args/captures/i24101/S2.scala +++ /dev/null @@ -1,14 +0,0 @@ -trait AttributeValue - -case class CompletedSpan( - name: String, // remove to make it compile - attributes: MyMap[String, AttributeValue], -){ - lazy val allAttributes: MyMap[String, AttributeValue] = attributes - var allAttributes2: MyMap[String, AttributeValue] = attributes -} - -def Test = - val span: CompletedSpan = ??? - span.copy(attributes = span.allAttributes.filterNot { _ => false }) - span.copy(attributes = span.allAttributes2.filterNot { _ => false }) \ No newline at end of file From 2818382fffd1fd8b0a73a7311a0b23a5576eb0f8 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 29 Sep 2025 21:34:03 +0200 Subject: [PATCH 3/3] Move test to regular test folder --- .../captures => pos}/clear-retains-for-inferred-types/S1.scala | 0 .../captures => pos}/clear-retains-for-inferred-types/S2.scala | 2 -- 2 files changed, 2 deletions(-) rename tests/{pos-custom-args/captures => pos}/clear-retains-for-inferred-types/S1.scala (100%) rename tests/{pos-custom-args/captures => pos}/clear-retains-for-inferred-types/S2.scala (94%) diff --git a/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S1.scala b/tests/pos/clear-retains-for-inferred-types/S1.scala similarity index 100% rename from tests/pos-custom-args/captures/clear-retains-for-inferred-types/S1.scala rename to tests/pos/clear-retains-for-inferred-types/S1.scala diff --git a/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala b/tests/pos/clear-retains-for-inferred-types/S2.scala similarity index 94% rename from tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala rename to tests/pos/clear-retains-for-inferred-types/S2.scala index 8f7d6a26698f..3e05fbcda8df 100644 --- a/tests/pos-custom-args/captures/clear-retains-for-inferred-types/S2.scala +++ b/tests/pos/clear-retains-for-inferred-types/S2.scala @@ -1,5 +1,3 @@ -import language.experimental.{captureChecking => _} - // i24101 trait AttributeValue