Skip to content

Commit 71eb7ac

Browse files
committed
Avoid another hardwired ConcreteAnnotation
# Conflicts: # compiler/src/dotty/tools/dotc/core/Types.scala
1 parent db91ae6 commit 71eb7ac

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ object Annotations {
6363
else if diff.exists then derivedAnnotation(tm.mapOver(tree))
6464
else this
6565

66+
/** Does this annotation refer to a parameter of `tl`?
67+
* Overridden in ConcreteAnnotation
68+
*/
69+
def refersToParamOf(tl: TermLambda)(using Context): Boolean = false
70+
6671
/** A string representation of the annotation.
6772
*/
68-
final def toText(printer: Printer): Text = printer.toText(this)
73+
def toText(printer: Printer): Text = printer.toText(this)
6974

7075
/** A text representing thge arguments of this annotation. Overridden in ConcreteAnnotation */
7176
def argsText(printer: Printer): Text = ""
@@ -77,7 +82,17 @@ object Annotations {
7782
}
7883

7984
case class ConcreteAnnotation(t: Tree) extends Annotation {
85+
8086
def tree(using Context): Tree = t
87+
88+
override def refersToParamOf(tl: TermLambda)(using Context): Boolean =
89+
tree.existsSubTree {
90+
case id: Ident => id.tpe match
91+
case TermParamRef(tl1, _) => tl eq tl1
92+
case _ => false
93+
case _ => false
94+
}
95+
8196
override def argsText(printer: Printer): Text =
8297
def toTextArg(arg: Tree): Text = arg match
8398
case Typed(SeqLiteral(elems, _), _) => printer.toTextGlobal(elems, ", ")

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,16 +3579,6 @@ object Types {
35793579
private var myDependencyStatus: DependencyStatus = Unknown
35803580
private var myParamDependencyStatus: DependencyStatus = Unknown
35813581

3582-
private def refersToParam(ann: Annotation)(using Context): Boolean = ann match
3583-
case ConcreteAnnotation(tree) =>
3584-
tree.existsSubTree {
3585-
case id: Ident => id.tpe match
3586-
case TermParamRef(`thisLambdaType`, _) => true
3587-
case _ => false
3588-
case _ => false
3589-
}
3590-
case _ => false
3591-
35923582
private def depStatus(initial: DependencyStatus, tp: Type)(using Context): DependencyStatus =
35933583
class DepAcc extends TypeAccumulator[DependencyStatus]:
35943584
def apply(status: DependencyStatus, tp: Type) = compute(status, tp, this)
@@ -3615,7 +3605,7 @@ object Types {
36153605
case tp: TypeVar if !tp.isInstantiated => combine(status, Provisional)
36163606
case tp: TermParamRef if tp.binder eq thisLambdaType => TrueDeps
36173607
case AnnotatedType(parent, ann) =>
3618-
if refersToParam(ann) then TrueDeps else compute(status, parent, theAcc)
3608+
if ann.refersToParamOf(thisLambdaType) then TrueDeps else compute(status, parent, theAcc)
36193609
case _: ThisType | _: BoundType | NoPrefix => status
36203610
case _ =>
36213611
(if theAcc != null then theAcc else DepAcc()).foldOver(status, tp)
@@ -3670,7 +3660,7 @@ object Types {
36703660
def apply(tp: Type) = tp match {
36713661
case tp @ TermParamRef(`thisLambdaType`, _) =>
36723662
range(defn.NothingType, atVariance(1)(apply(tp.underlying)))
3673-
case AnnotatedType(parent, ann) if refersToParam(ann) =>
3663+
case AnnotatedType(parent, ann) if ann.refersToParamOf(thisLambdaType) =>
36743664
mapOver(parent)
36753665
case _ => mapOver(tp)
36763666
}

0 commit comments

Comments
 (0)