Skip to content

Commit 86e35e4

Browse files
committed
Use symbolic refs when testing whether a TypeBounds contains a ClassInfo
Without the fix and the later commit that checks types for overriding we get a Ycheck failure in t3452h.scala.
1 parent 8103c64 commit 86e35e4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Diff for: src/dotty/tools/dotc/core/TypeComparer.scala

+5-6
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
434434
(tp2.variance > 0 && tp1.variance >= 0 || (lo2 eq NothingType) || isSubType(lo2, lo1)) &&
435435
(tp2.variance < 0 && tp1.variance <= 0 || (hi2 eq AnyType) || isSubType(hi1, hi2))
436436
case tp1: ClassInfo =>
437-
val tt = tp1.typeRef
438-
isSubType(lo2, tt) && isSubType(tt, hi2)
437+
tp2 contains tp1
439438
case _ =>
440439
false
441440
}
@@ -1063,13 +1062,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10631062
case tp1: TypeBounds =>
10641063
tp2 match {
10651064
case tp2: TypeBounds => tp1 & tp2
1066-
case tp2: ClassInfo if tp1 contains tp2.typeRef => tp2
1065+
case tp2: ClassInfo if tp1 contains tp2 => tp2
10671066
case _ => mergeConflict(tp1, tp2)
10681067
}
10691068
case tp1: ClassInfo =>
10701069
tp2 match {
10711070
case tp2: ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix & tp2.prefix)
1072-
case tp2: TypeBounds if tp2 contains tp1.typeRef => tp1
1071+
case tp2: TypeBounds if tp2 contains tp1 => tp1
10731072
case _ => mergeConflict(tp1, tp2)
10741073
}
10751074
case tp1 @ MethodType(names1, formals1) =>
@@ -1122,13 +1121,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
11221121
case tp1: TypeBounds =>
11231122
tp2 match {
11241123
case tp2: TypeBounds => tp1 | tp2
1125-
case tp2: ClassInfo if tp1 contains tp2.typeRef => tp1
1124+
case tp2: ClassInfo if tp1 contains tp2 => tp1
11261125
case _ => mergeConflict(tp1, tp2)
11271126
}
11281127
case tp1: ClassInfo =>
11291128
tp2 match {
11301129
case tp2: ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix | tp2.prefix)
1131-
case tp2: TypeBounds if tp2 contains tp1.typeRef => tp2
1130+
case tp2: TypeBounds if tp2 contains tp1 => tp2
11321131
case _ => mergeConflict(tp1, tp2)
11331132
}
11341133
case tp1 @ MethodType(names1, formals1) =>

Diff for: src/dotty/tools/dotc/core/Types.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -2663,11 +2663,13 @@ object Types {
26632663
def clsDenot = if (prefix eq cls.owner.thisType) cls.denot else cls.denot.copySymDenotation(info = this)
26642664
if (typeRefCache == null)
26652665
typeRefCache =
2666-
if ((cls is PackageClass) || cls.owner.isTerm) prefix select cls
2667-
else prefix select (cls.name, clsDenot)
2666+
if ((cls is PackageClass) || cls.owner.isTerm) symbolicTypeRef
2667+
else TypeRef(prefix, cls.name, clsDenot)
26682668
typeRefCache
26692669
}
26702670

2671+
def symbolicTypeRef(implicit ctx: Context): Type = TypeRef(prefix, cls)
2672+
26712673
// cached because baseType needs parents
26722674
private var parentsCache: List[TypeRef] = null
26732675

@@ -2732,8 +2734,12 @@ object Types {
27322734
case _ => this
27332735
}
27342736

2735-
def contains(tp: Type)(implicit ctx: Context) = tp match {
2737+
def contains(tp: Type)(implicit ctx: Context): Boolean = tp match {
27362738
case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi
2739+
case tp: ClassInfo =>
2740+
// Note: Taking a normal typeRef does not work here. A normal ref might contain
2741+
// also other information about the named type (e.g. bounds).
2742+
contains(tp.symbolicTypeRef)
27372743
case _ => lo <:< tp && tp <:< hi
27382744
}
27392745

0 commit comments

Comments
 (0)