Skip to content

Commit e64c561

Browse files
committed
Transform annotations only if defined in current run
There's no point transforming annotations that come from classfiles. It's inefficient to do so and it's also risky because it means we'd have to make sense of Scala-2 generated trees. This should avoid the error in #1222.
1 parent 96fcdd9 commit e64c561

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/dotty/tools/dotc/transform/TreeTransform.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,19 @@ object TreeTransforms {
185185

186186
ref match {
187187
case ref: SymDenotation =>
188-
val annotTrees = ref.annotations.map(_.tree)
189-
val annotTrees1 = annotTrees.mapConserve(annotationTransformer.macroTransform)
190-
val annots1 = if (annotTrees eq annotTrees1) ref.annotations else annotTrees1.map(new ConcreteAnnotation(_))
188+
val annots1 =
189+
if (!ref.symbol.isDefinedInCurrentRun) ref.annotations // leave annotations read from class files alone
190+
else {
191+
val annotTrees = ref.annotations.map(_.tree)
192+
val annotTrees1 = annotTrees.mapConserve(annotationTransformer.macroTransform)
193+
if (annotTrees eq annotTrees1) ref.annotations
194+
else annotTrees1.map(new ConcreteAnnotation(_))
195+
}
191196
if ((info1 eq ref.info) && (annots1 eq ref.annotations)) ref
192197
else ref.copySymDenotation(info = info1, annotations = annots1)
193-
case _ => if (info1 eq ref.info) ref else ref.derivedSingleDenotation(ref.symbol, info1)
198+
case _ =>
199+
if (info1 eq ref.info) ref
200+
else ref.derivedSingleDenotation(ref.symbol, info1)
194201
}
195202
}
196203
}

0 commit comments

Comments
 (0)