diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index e809c0fad463..4a35830ae554 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -301,12 +301,9 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => // during the typer, it is infeasible to correctly infer the capture sets in most // cases, resulting ill-formed capture sets that could crash the pickler later on. // See #20035. - private def cleanupRetainsAnnot(symbol: Symbol, tpt: Tree)(using Context): Tree = + private def cleanupRetainsAnnot(tpt: Tree)(using Context): Tree = tpt match - case tpt: InferredTypeTree - if !symbol.allOverriddenSymbols.hasNext => - // if there are overridden symbols, the annotation comes from an explicit type of the overridden symbol - // and should be retained. + case tpt: InferredTypeTree => val tm = new CleanupRetains val tpe1 = tm(tpt.tpe) tpt.withType(tpe1) @@ -421,7 +418,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => registerIfHasMacroAnnotations(tree) checkErasedDef(tree) Checking.checkPolyFunctionType(tree.tpt) - val tree1 = cpy.ValDef(tree)(tpt = cleanupRetainsAnnot(tree.symbol, tree.tpt), rhs = normalizeErasedRhs(tree.rhs, tree.symbol)) + val tree1 = cpy.ValDef(tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol)) if tree1.removeAttachment(desugar.UntupledParam).isDefined then checkStableSelection(tree.rhs) processValOrDefDef(super.transform(tree1)) @@ -431,7 +428,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => checkErasedDef(tree) Checking.checkPolyFunctionType(tree.tpt) annotateContextResults(tree) - val tree1 = cpy.DefDef(tree)(tpt = cleanupRetainsAnnot(tree.symbol, tree.tpt), rhs = normalizeErasedRhs(tree.rhs, tree.symbol)) + val tree1 = cpy.DefDef(tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol)) processValOrDefDef(superAcc.wrapDefDef(tree1)(super.transform(tree1).asInstanceOf[DefDef])) case tree: TypeDef => registerIfHasMacroAnnotations(tree) @@ -504,8 +501,9 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => report.error(em"type ${alias.tpe} outside bounds $bounds", tree.srcPos) super.transform(tree) case tree: TypeTree => - tree.withType( - tree.tpe match { + val tree1 = cleanupRetainsAnnot(tree) + tree1.withType( + tree1.tpe match { case AnnotatedType(tpe, annot) => AnnotatedType(tpe, transformAnnot(annot)) case tpe => tpe } diff --git a/tests/pos-custom-args/captures/i20272a.scala b/tests/pos-custom-args/captures/i20272a.scala new file mode 100644 index 000000000000..5a4a5d1ce0b8 --- /dev/null +++ b/tests/pos-custom-args/captures/i20272a.scala @@ -0,0 +1,20 @@ +import language.experimental.captureChecking + +trait Iterable[T] { self: Iterable[T]^ => + def map[U](f: T => U): Iterable[U]^{this, f} +} + +object Test { + def assertEquals[A, B](a: A, b: B): Boolean = ??? + + def foo[T](level: Int, lines: Iterable[T]) = + lines.map(x => x) + + def bar(messages: Iterable[String]) = + foo(1, messages) + + val it: Iterable[String] = ??? + val msgs = bar(it) + + assertEquals(msgs, msgs) +} diff --git a/tests/pos-custom-args/captures/i20272b.scala b/tests/pos-custom-args/captures/i20272b.scala new file mode 100644 index 000000000000..b5f69aecd95d --- /dev/null +++ b/tests/pos-custom-args/captures/i20272b.scala @@ -0,0 +1,16 @@ +import language.experimental.captureChecking + +trait Iterable[T] { self: Iterable[T]^ => + def map[U](f: T => U): Iterable[U]^{this, f} +} + +object Test { + def foo[T](level: Int, lines: Iterable[T]) = + lines.map(x => x) + + class Bar: + def bar(messages: Iterable[String]) = + foo(1, messages) + class Baz extends Bar: + override def bar(messages: Iterable[String]) = ??? +}