From f2896413eff7413a4786d92a2d4aba57ee366150 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Wed, 27 Mar 2024 15:19:15 +0100 Subject: [PATCH] Fix the mapping of term-dependent annotations --- compiler/src/dotty/tools/dotc/core/Annotations.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 45dba97a79f7..8ff90d3ca9bc 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -7,6 +7,7 @@ import ast.tpd, tpd.* import util.Spans.Span import printing.{Showable, Printer} import printing.Texts.Text +import cc.isRetainsLike import scala.annotation.internal.sharable @@ -65,7 +66,7 @@ object Annotations { foldOver(if 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 derivedAnnotation(tm.mapOver(tree)) + else if diff.exists || symbol.isRetainsLike then derivedAnnotation(tm.mapOver(tree)) else this /** Does this annotation refer to a parameter of `tl`? */ @@ -73,9 +74,13 @@ object Annotations { val args = arguments if args.isEmpty then false else tree.existsSubTree: - case id: (Ident | This) => id.tpe.stripped match + case id: Ident => id.tpe.stripped match case TermParamRef(tl1, _) => tl eq tl1 case _ => false + case ref: This => ref.tpe match + case TermParamRef(tl1, _) => tl eq tl1 + case AnnotatedType(tp1, annot1) => annot1.refersToParamOf(tl) + case _ => false case _ => false /** A string representation of the annotation. Overridden in BodyAnnotation.