Skip to content

Commit f84bedd

Browse files
committed
Handle QualifiedAnnotation in TypeAccumulator
1 parent b9ba524 commit f84bedd

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import cc.*
4343
import CaptureSet.IdentityCaptRefMap
4444
import Capabilities.*
4545
import transform.Recheck.currentRechecker
46-
import qualified_types.QualifiedType
46+
import qualified_types.{QualifiedType, QualifiedAnnotation}
4747
import scala.annotation.internal.sharable
4848
import scala.annotation.threadUnsafe
4949

@@ -5023,6 +5023,7 @@ object Types extends TypeUtils {
50235023

50245024
private var myRepr: Name | Null = null
50255025
def repr(using Context): Name = {
5026+
//if (myRepr == null) myRepr = s"?$id".toString.toTermName
50265027
if (myRepr == null) myRepr = SkolemName.fresh()
50275028
myRepr.nn
50285029
}
@@ -6954,7 +6955,10 @@ object Types extends TypeUtils {
69546955

69556956
def apply(x: T, tp: Type): T
69566957

6957-
protected def applyToAnnot(x: T, annot: Annotation): T = x // don't go into annotations
6958+
protected def applyToAnnot(x: T, annot: Annotation): T =
6959+
annot match
6960+
case annot: QualifiedAnnotation => annot.foldOverTypes(x, this)
6961+
case _ => x // don't go into other annotations
69586962

69596963
/** A prefix is never contravariant. Even if say `p.A` is used in a contravariant
69606964
* 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)