File tree 1 file changed +10
-4
lines changed
src/dotty/tools/dotc/core
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -780,11 +780,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
780
780
val t2 = mergeIfSub(tp2, tp1)
781
781
if (t2.exists) t2
782
782
else tp1 match {
783
- case tp1 : SingletonType =>
783
+ case tp1 : ConstantType =>
784
784
tp2 match {
785
- case tp2 : SingletonType =>
786
- // Make use of the fact that the intersection of two singleton
787
- // types which are not subtypes of each other is empty.
785
+ case tp2 : ConstantType =>
786
+ // Make use of the fact that the intersection of two constant types
787
+ // types which are not subtypes of each other is known to be empty.
788
+ // Note: The same does not apply to singleton types in general.
789
+ // E.g. we could have a pattern match against `x.type & y.type`
790
+ // which might succeed if `x` and `y` happen to be the same ref
791
+ // at run time. It would not work to replace that with `Nothing`.
792
+ // However, maybe we can still apply the replacement to
793
+ // types which are not explicitly written.
788
794
defn.NothingType
789
795
case _ => andType(tp1, tp2)
790
796
}
You can’t perform that action at this time.
0 commit comments