Skip to content

Commit

Permalink
Fix the mapping of term-dependent annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Mar 27, 2024
1 parent 7171211 commit f289641
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -65,17 +66,21 @@ 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`? */
def refersToParamOf(tl: TermLambda)(using Context): Boolean =
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.
Expand Down

0 comments on commit f289641

Please sign in to comment.