diff --git a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala index c79e75895a7b..98d9a0ca85f6 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -21,9 +21,6 @@ import Decorators.* * @param newOwners New owners, replacing previous owners. * @param substFrom The symbols that need to be substituted. * @param substTo The substitution targets. - * @param cpy A tree copier that is used to create new trees. - * @param alwaysCopySymbols If set, symbols are always copied, even when they - * are not impacted by the transformation. * * The reason the substitution is broken out from the rest of the type map is * that all symbols have to be substituted at the same time. If we do not do this, @@ -41,9 +38,7 @@ class TreeTypeMap( val newOwners: List[Symbol] = Nil, val substFrom: List[Symbol] = Nil, val substTo: List[Symbol] = Nil, - cpy: tpd.TreeCopier = tpd.cpy, - alwaysCopySymbols: Boolean = false, -)(using Context) extends tpd.TreeMap(cpy) { + cpy: tpd.TreeCopier = tpd.cpy)(using Context) extends tpd.TreeMap(cpy) { import tpd.* def copy( @@ -53,7 +48,7 @@ class TreeTypeMap( newOwners: List[Symbol], substFrom: List[Symbol], substTo: List[Symbol])(using Context): TreeTypeMap = - new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols) + new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo) /** If `sym` is one of `oldOwners`, replace by corresponding symbol in `newOwners` */ def mapOwner(sym: Symbol): Symbol = sym.subst(oldOwners, newOwners) @@ -212,7 +207,7 @@ class TreeTypeMap( * between original and mapped symbols. */ def withMappedSyms(syms: List[Symbol]): TreeTypeMap = - withMappedSyms(syms, mapSymbols(syms, this, mapAlways = alwaysCopySymbols)) + withMappedSyms(syms, mapSymbols(syms, this)) /** The tree map with the substitution between originals `syms` * and mapped symbols `mapped`. Also goes into mapped classes @@ -234,10 +229,6 @@ class TreeTypeMap( tmap1 } - def withAlwaysCopySymbols: TreeTypeMap = - if alwaysCopySymbols then this - else new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols = true) - override def toString = def showSyms(syms: List[Symbol]) = syms.map(sym => s"$sym#${sym.id}").mkString(", ") diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 08e206b1a850..d6a99b12e3b3 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -3,9 +3,8 @@ package dotc package core import Symbols.*, Types.*, Contexts.*, Constants.*, Phases.* -import ast.{tpd, untpd, TreeTypeMap} -import tpd.* -import util.Spans.{Span, NoSpan} +import ast.tpd, tpd.* +import util.Spans.Span import printing.{Showable, Printer} import printing.Texts.Text @@ -69,12 +68,7 @@ object Annotations { foldOver(if !tp1.exists || (tp1 frozen_=:= tree.tpe) then x else tp1, tree) val diff = findDiff(NoType, args) if tm.isRange(diff) then EmptyAnnotation - else if diff.exists then - // If the annotation has been transformed, we need to make sure that the - // symbol are copied so that we don't end up with the same symbol in different - // trees, which would lead to a crash in pickling. - val mappedTree = TreeTypeMap(typeMap = tm, alwaysCopySymbols = true).transform(tree) - derivedAnnotation(mappedTree) + else if diff.exists then derivedAnnotation(tm.mapOver(tree)) else this /** Does this annotation refer to a parameter of `tl`? */ diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index af8721d2a479..0feee53ca50f 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -2,7 +2,7 @@ package dotty.tools package dotc package transform -import dotty.tools.dotc.ast.{Trees, TreeTypeMap, tpd, untpd, desugar} +import dotty.tools.dotc.ast.{Trees, tpd, untpd, desugar} import scala.collection.mutable import core.* import dotty.tools.dotc.typer.Checking @@ -158,14 +158,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => val saved = inJavaAnnot inJavaAnnot = annot.symbol.is(JavaDefined) if (inJavaAnnot) checkValidJavaAnnotation(annot) - try - val res = transform(annot) - if res ne annot then - // If the annotation has been transformed, we need to make sure that the - // symbol are copied so that we don't end up with the same symbol in different - // trees, which would lead to a crash in pickling. - TreeTypeMap(alwaysCopySymbols = true)(res) - else res + try transform(annot) finally inJavaAnnot = saved } diff --git a/tests/pos/annot-17939.scala b/tests/pos/annot-17939.scala deleted file mode 100644 index 2b3adf0ac1cc..000000000000 --- a/tests/pos/annot-17939.scala +++ /dev/null @@ -1,7 +0,0 @@ -class qualified[T](f: T => Boolean) extends annotation.StaticAnnotation - -class Box[T](val x: T) -class Box2(val x: Int) - -class A(a: String @qualified((x: Int) => Box(3).x == 3)) // crash -class A2(a2: String @qualified((x: Int) => Box2(3).x == 3)) // works diff --git a/tests/pos/annot-17939c.scala b/tests/pos/annot-17939c.scala deleted file mode 100644 index 5babdf389114..000000000000 --- a/tests/pos/annot-17939c.scala +++ /dev/null @@ -1,5 +0,0 @@ -class qualified(f: Int => Boolean) extends annotation.StaticAnnotation -class Box[T](val y: T) -def Test = - val x: String @qualified((x: Int) => Box(42).y == 2) = ??? - val y = x diff --git a/tests/pos/annot-19846.scala b/tests/pos/annot-19846.scala deleted file mode 100644 index 09c24a5cf3cf..000000000000 --- a/tests/pos/annot-19846.scala +++ /dev/null @@ -1,8 +0,0 @@ -class qualified[T](predicate: T => Boolean) extends annotation.StaticAnnotation - -class EqualPair(val x: Int, val y: Int @qualified[Int](it => it == x)) - -@main def main = - val p = EqualPair(42, 42) - val y = p.y - println(42) diff --git a/tests/pos/annot-19846b.scala b/tests/pos/annot-19846b.scala deleted file mode 100644 index 951a3c8116ff..000000000000 --- a/tests/pos/annot-19846b.scala +++ /dev/null @@ -1,7 +0,0 @@ -class lambdaAnnot(g: () => Int) extends annotation.StaticAnnotation - -def f(x: Int): Int @lambdaAnnot(() => x) = x - -object Test: - val y: Int = ??? - val z /* : Int @lambdaAnnot(() => y) */ = f(y)