Skip to content

Commit 46fcf2f

Browse files
authored
Harden Annotation.refersToParamOf (#24647)
We now also do the correct thing for term trees with embedded TypeTree nodes.
2 parents 93e58da + 8bba937 commit 46fcf2f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,18 @@ object Annotations {
117117
def isLambdaParam(t: Type) = t match
118118
case TermParamRef(tl1, _) => tl eq tl1
119119
case _ => false
120-
tpd.allArguments(tree).exists: arg =>
121-
if arg.isType then
122-
arg.tpe.existsPart(isLambdaParam, stopAt = StopAt.Static)
123-
else
124-
arg.existsSubTree:
120+
121+
val acc = new TreeAccumulator[Boolean]:
122+
def apply(x: Boolean, t: Tree)(using Context) =
123+
if x then true
124+
else if t.isType then
125+
t.tpe.existsPart(isLambdaParam, stopAt = StopAt.Static)
126+
else t match
125127
case id: (Ident | This) => isLambdaParam(id.tpe.stripped)
126-
case _ => false
128+
case _ => foldOver(x, t)
129+
130+
tpd.allArguments(tree).exists(acc(false, _))
131+
end refersToParamOf
127132

128133
/** A string representation of the annotation. Overridden in BodyAnnotation.
129134
*/

0 commit comments

Comments
 (0)