Skip to content

Commit cf6e895

Browse files
committed
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 207d878 commit cf6e895

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
297297
thirdTry
298298
case tp1: TypeParamRef =>
299299
def flagNothingBound = {
300-
if (!frozenConstraint && tp2.isRef(defn.NothingClass) && state.isGlobalCommittable) {
300+
if (!frozenConstraint && tp2.isRef(NothingClass) && state.isGlobalCommittable) {
301301
def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}"
302302
if (Config.failOnInstantiationToNothing) assert(false, msg)
303303
else ctx.log(msg)
@@ -379,8 +379,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
379379
if (cls2.isClass) {
380380
if (cls2.typeParams.isEmpty) {
381381
if (cls2 eq AnyKindClass) return true
382-
if (tp1.isRef(defn.NothingClass)) return true
382+
if (tp1.isRef(NothingClass)) return true
383383
if (tp1.isLambdaSub) return false
384+
if (cls2 eq AnyClass) return true
384385
// Note: We would like to replace this by `if (tp1.hasHigherKind)`
385386
// but right now we cannot since some parts of the standard library rely on the
386387
// idiom that e.g. `List <: Any`. We have to bootstrap without scalac first.
@@ -394,7 +395,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
394395
val base = tp1.baseType(cls2)
395396
if (base.typeSymbol == cls2) return true
396397
}
397-
else if (tp1.isLambdaSub && !tp1.isRef(defn.AnyKindClass))
398+
else if (tp1.isLambdaSub && !tp1.isRef(AnyKindClass))
398399
return recur(tp1, EtaExpansion(cls2.typeRef))
399400
}
400401
fourthTry
@@ -1257,7 +1258,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12571258
// at run time. It would not work to replace that with `Nothing`.
12581259
// However, maybe we can still apply the replacement to
12591260
// types which are not explicitly written.
1260-
defn.NothingType
1261+
NothingType
12611262
case _ => andType(tp1, tp2)
12621263
}
12631264
case _ => andType(tp1, tp2)
@@ -1268,8 +1269,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12681269
}
12691270

12701271
/** The greatest lower bound of a list types */
1271-
final def glb(tps: List[Type]): Type =
1272-
((defn.AnyType: Type) /: tps)(glb)
1272+
final def glb(tps: List[Type]): Type = ((AnyType: Type) /: tps)(glb)
12731273

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

13001300
/** The least upper bound of a list of types */
13011301
final def lub(tps: List[Type]): Type =
1302-
((defn.NothingType: Type) /: tps)(lub(_,_, canConstrain = false))
1302+
((NothingType: Type) /: tps)(lub(_,_, canConstrain = false))
13031303

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4143,7 +4143,7 @@ object Types {
41434143
forwarded.orElse(
41444144
range(super.derivedSelect(tp, preLo), super.derivedSelect(tp, preHi)))
41454145
case _ =>
4146-
if (pre == defn.AnyType) pre else super.derivedSelect(tp, pre)
4146+
super.derivedSelect(tp, pre)
41474147
}
41484148

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

0 commit comments

Comments
 (0)