Skip to content

Commit 01312c9

Browse files
committed
Handle QualifiedAnnotation in TypeAccumulator
1 parent 24eeb58 commit 01312c9

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 8e4a40588491608aa40099f79c881d54a5094e75

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

@@ -5018,6 +5018,7 @@ object Types extends TypeUtils {
50185018

50195019
private var myRepr: Name | Null = null
50205020
def repr(using Context): Name = {
5021+
//if (myRepr == null) myRepr = s"?$id".toString.toTermName
50215022
if (myRepr == null) myRepr = SkolemName.fresh()
50225023
myRepr.nn
50235024
}
@@ -6944,7 +6945,10 @@ object Types extends TypeUtils {
69446945

69456946
def apply(x: T, tp: Type): T
69466947

6947-
protected def applyToAnnot(x: T, annot: Annotation): T = x // don't go into annotations
6948+
protected def applyToAnnot(x: T, annot: Annotation): T =
6949+
annot match
6950+
case annot: QualifiedAnnotation => annot.foldOverTypes(x, this)
6951+
case _ => x // don't go into other annotations
69486952

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