Skip to content

Commit c4e8236

Browse files
committed
Handle QualifiedAnnotation in TypeAccumulator
1 parent 95451ef commit c4e8236

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4970,6 +4970,7 @@ object Types extends TypeUtils {
49704970

49714971
private var myRepr: Name | Null = null
49724972
def repr(using Context): Name = {
4973+
//if (myRepr == null) myRepr = s"?$id".toString.toTermName
49734974
if (myRepr == null) myRepr = SkolemName.fresh()
49744975
myRepr.nn
49754976
}
@@ -6884,7 +6885,10 @@ object Types extends TypeUtils {
68846885

68856886
def apply(x: T, tp: Type): T
68866887

6887-
protected def applyToAnnot(x: T, annot: Annotation): T = x // don't go into annotations
6888+
protected def applyToAnnot(x: T, annot: Annotation): T =
6889+
annot match
6890+
case annot: QualifiedAnnotation => annot.foldOverTypes(x, this)
6891+
case _ => x // don't go into other annotations
68886892

68896893
/** A prefix is never contravariant. Even if say `p.A` is used in a contravariant
68906894
* context, we cannot assume contravariance for `p` because `p`'s lower

compiler/src/dotty/tools/dotc/qualified_types/ENode.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,16 @@ enum ENode extends Showable:
249249
body.foreachType(f)
250250

251251
def normalizeTypes()(using Context): ENode =
252-
mapTypes(NormalizeMap())
252+
trace(i"normalizeTypes($this)", Printers.qualifiedTypes):
253+
mapTypes(NormalizeMap())
253254

254255
private class NormalizeMap(using Context) extends TypeMap:
255256
def apply(tp: Type): Type =
256257
tp match
257258
case tp: TypeVar if tp.isPermanentlyInstantiated =>
258259
apply(tp.permanentInst)
259260
case tp: NamedType =>
260-
val dealiased = tp.dealias
261+
val dealiased = tp.dealiasKeepAnnotsAndOpaques
261262
if dealiased ne tp then
262263
apply(dealiased)
263264
else if tp.symbol.isStatic then
@@ -547,7 +548,7 @@ object ENode:
547548
def assumptions(node: ENode)(using Context): List[ENode] =
548549
trace(i"assumptions($node)", Printers.qualifiedTypes):
549550
node match
550-
case Atom(tp: SingletonType) => termAssumptions(tp) ++ typeAssumptions(tp)
551+
case n: Atom => termAssumptions(n.tp) ++ typeAssumptions(n.tp)
551552
case n: Constructor => Nil
552553
case n: Select => assumptions(n.qual)
553554
case n: Apply => assumptions(n.fn) ++ n.args.flatMap(assumptions)
@@ -560,7 +561,6 @@ object ENode:
560561
tp match
561562
case tp: TermRef =>
562563
tp.symbol.info match
563-
case QualifiedType(_, _) => Nil
564564
case _ =>
565565
tp.symbol.defTree match
566566
case valDef: tpd.ValDef if !valDef.rhs.isEmpty && !valDef.symbol.is(Flags.Lazy) =>

compiler/src/dotty/tools/dotc/qualified_types/QualifiedAnnotation.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ case class QualifiedAnnotation(qualifier: ENode.Lambda) extends Annotation:
3737
case TermParamRef(tl1, _) if tl eq tl1 => res = true
3838
case _ => ()
3939
res
40+
41+
def foldOverTypes[A](z: A, f: (A, Type) => A)(using Context): A =
42+
var acc = z
43+
qualifier.foreachType: tp =>
44+
acc = f(acc, tp)
45+
acc

0 commit comments

Comments
 (0)