Skip to content

Commit b3dd07c

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 f7b08b6 commit b3dd07c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
319319
thirdTry
320320
case tp1: TypeParamRef =>
321321
def flagNothingBound = {
322-
if (!frozenConstraint && tp2.isRef(defn.NothingClass) && state.isGlobalCommittable) {
322+
if (!frozenConstraint && tp2.isRef(NothingClass) && state.isGlobalCommittable) {
323323
def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}"
324324
if (Config.failOnInstantiationToNothing) assert(false, msg)
325325
else ctx.log(msg)
@@ -404,8 +404,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
404404
if (cls2.isClass) {
405405
if (cls2.typeParams.isEmpty) {
406406
if (cls2 eq AnyKindClass) return true
407-
if (tp1.isRef(defn.NothingClass)) return true
407+
if (tp1.isRef(NothingClass)) return true
408408
if (tp1.isLambdaSub) return false
409+
if (cls2 eq AnyClass) return true
409410
// Note: We would like to replace this by `if (tp1.hasHigherKind)`
410411
// but right now we cannot since some parts of the standard library rely on the
411412
// idiom that e.g. `List <: Any`. We have to bootstrap without scalac first.
@@ -417,7 +418,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
417418
val base = tp1.baseType(cls2)
418419
if (base.typeSymbol == cls2) return true
419420
}
420-
else if (tp1.isLambdaSub && !tp1.isRef(defn.AnyKindClass))
421+
else if (tp1.isLambdaSub && !tp1.isRef(AnyKindClass))
421422
return recur(tp1, EtaExpansion(cls2.typeRef))
422423
}
423424
fourthTry
@@ -1382,7 +1383,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
13821383
// at run time. It would not work to replace that with `Nothing`.
13831384
// However, maybe we can still apply the replacement to
13841385
// types which are not explicitly written.
1385-
defn.NothingType
1386+
NothingType
13861387
case _ => andType(tp1, tp2)
13871388
}
13881389
case _ => andType(tp1, tp2)
@@ -1393,8 +1394,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
13931394
}
13941395

13951396
/** The greatest lower bound of a list types */
1396-
final def glb(tps: List[Type]): Type =
1397-
((defn.AnyType: Type) /: tps)(glb)
1397+
final def glb(tps: List[Type]): Type = ((AnyType: Type) /: tps)(glb)
13981398

13991399
/** The least upper bound of two types
14001400
* @param canConstrain If true, new constraints might be added to simplify the lub.
@@ -1424,7 +1424,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
14241424

14251425
/** The least upper bound of a list of types */
14261426
final def lub(tps: List[Type]): Type =
1427-
((defn.NothingType: Type) /: tps)(lub(_,_, canConstrain = false))
1427+
((NothingType: Type) /: tps)(lub(_,_, canConstrain = false))
14281428

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

0 commit comments

Comments
 (0)