@@ -48,6 +48,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
48
48
private var myAnyClass : ClassSymbol = null
49
49
private var myNothingClass : ClassSymbol = null
50
50
private var myNullClass : ClassSymbol = null
51
+ private var myPhantomAnyClass : ClassSymbol = null
51
52
private var myPhantomNothingClass : ClassSymbol = null
52
53
private var myObjectClass : ClassSymbol = null
53
54
private var myAnyType : TypeRef = null
@@ -65,7 +66,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
65
66
if (myNullClass == null ) myNullClass = defn.NullClass
66
67
myNullClass
67
68
}
68
- def PhantomNothing = {
69
+ def PhantomAnyClass = {
70
+ if (myPhantomAnyClass == null ) myPhantomAnyClass = defn.PhantomAny
71
+ myPhantomAnyClass
72
+ }
73
+ def PhantomNothingClass = {
69
74
if (myPhantomNothingClass == null ) myPhantomNothingClass = defn.PhantomNothing
70
75
myPhantomNothingClass
71
76
}
@@ -556,10 +561,16 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
556
561
case OrType (tp1, tp2) => isNullable(tp1) || isNullable(tp2)
557
562
case _ => false
558
563
}
559
- if (tp1.symbol eq NothingClass ) tp2.isValueTypeOrLambda && (tp2.topType.classSymbol eq AnyClass )
560
- else if (tp1.symbol eq NullClass ) isNullable(tp2) && (tp2.topType.classSymbol eq AnyClass )
561
- else if (tp1.symbol eq PhantomNothing ) tp2.isValueTypeOrLambda && (tp1.topType == tp2.topType)
562
- else false
564
+ def isPhantom (tp : Type ): Boolean = {
565
+ // note that the only phantom classes are PhantomAnyClass and PhantomNothingClass
566
+ val sym = tp.typeSymbol
567
+ (sym eq PhantomAnyClass ) || (sym eq PhantomNothingClass ) ||
568
+ (! sym.isClass && (tp.topType.classSymbol eq PhantomAnyClass ))
569
+ }
570
+ val sym1 = tp1.symbol
571
+ (sym1 eq NothingClass ) && tp2.isValueTypeOrLambda && ! isPhantom(tp2) ||
572
+ (sym1 eq NullClass ) && isNullable(tp2) ||
573
+ (sym1 eq PhantomNothingClass ) && tp1.topType == tp2.topType
563
574
}
564
575
case tp1 : SingletonType =>
565
576
/** if `tp2 == p.type` and `p: q.type` then try `tp1 <:< q.type` as a last effort.*/
0 commit comments