Skip to content

Commit 7659c11

Browse files
oderskyBlaisorblade
authored andcommitted
Special case comparison with Any
Add the rule T <: Any for any *-Type T. This was not include fully before. We did have the rule that T <: Any, if Any is in the base types of T. However, it could be that the base type wrt Any does not exist. Example: Any#L <: Any yielded false before, now yields true. This error manifested itself in i4031.scala. With the new rule, we can drop again the special case in derivedSelect.
1 parent bd55b74 commit 7659c11

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
302302
thirdTry
303303
case tp1: TypeParamRef =>
304304
def flagNothingBound = {
305-
if (!frozenConstraint && tp2.isRef(defn.NothingClass) && state.isGlobalCommittable) {
305+
if (!frozenConstraint && tp2.isRef(NothingClass) && state.isGlobalCommittable) {
306306
def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}"
307307
if (Config.failOnInstantiationToNothing) assert(false, msg)
308308
else ctx.log(msg)
@@ -384,8 +384,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
384384
if (cls2.isClass) {
385385
if (cls2.typeParams.isEmpty) {
386386
if (cls2 eq AnyKindClass) return true
387-
if (tp1.isRef(defn.NothingClass)) return true
387+
if (tp1.isRef(NothingClass)) return true
388388
if (tp1.isLambdaSub) return false
389+
if (cls2 eq AnyClass) return true
389390
// Note: We would like to replace this by `if (tp1.hasHigherKind)`
390391
// but right now we cannot since some parts of the standard library rely on the
391392
// idiom that e.g. `List <: Any`. We have to bootstrap without scalac first.
@@ -399,7 +400,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
399400
val base = tp1.baseType(cls2)
400401
if (base.typeSymbol == cls2) return true
401402
}
402-
else if (tp1.isLambdaSub && !tp1.isRef(defn.AnyKindClass))
403+
else if (tp1.isLambdaSub && !tp1.isRef(AnyKindClass))
403404
return recur(tp1, EtaExpansion(cls2.typeRef))
404405
}
405406
fourthTry
@@ -1296,7 +1297,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12961297
// at run time. It would not work to replace that with `Nothing`.
12971298
// However, maybe we can still apply the replacement to
12981299
// types which are not explicitly written.
1299-
defn.NothingType
1300+
NothingType
13001301
case _ => andType(tp1, tp2)
13011302
}
13021303
case _ => andType(tp1, tp2)
@@ -1307,8 +1308,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
13071308
}
13081309

13091310
/** The greatest lower bound of a list types */
1310-
final def glb(tps: List[Type]): Type =
1311-
((defn.AnyType: Type) /: tps)(glb)
1311+
final def glb(tps: List[Type]): Type = ((AnyType: Type) /: tps)(glb)
13121312

13131313
/** The least upper bound of two types
13141314
* @param canConstrain If true, new constraints might be added to simplify the lub.
@@ -1338,7 +1338,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
13381338

13391339
/** The least upper bound of a list of types */
13401340
final def lub(tps: List[Type]): Type =
1341-
((defn.NothingType: Type) /: tps)(lub(_,_, canConstrain = false))
1341+
((NothingType: Type) /: tps)(lub(_,_, canConstrain = false))
13421342

13431343
/** Try to produce joint arguments for a lub `A[T_1, ..., T_n] | A[T_1', ..., T_n']` using
13441344
* the following strategies:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4267,7 +4267,7 @@ object Types {
42674267
forwarded.orElse(
42684268
range(super.derivedSelect(tp, preLo), super.derivedSelect(tp, preHi)))
42694269
case _ =>
4270-
if (pre == defn.AnyType) pre else super.derivedSelect(tp, pre)
4270+
super.derivedSelect(tp, pre)
42714271
}
42724272

42734273
override protected def derivedRefinedType(tp: RefinedType, parent: Type, info: Type) =

0 commit comments

Comments
 (0)