File tree 1 file changed +6
-7
lines changed
compiler/src/dotty/tools/dotc/typer
1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -812,9 +812,7 @@ trait Implicits { self: Typer =>
812
812
cmpWithBoxed(cls1, cls2)
813
813
else if (cls2.isPrimitiveValueClass)
814
814
cmpWithBoxed(cls2, cls1)
815
- else if (cls1 == defn.NullClass && cls1 == cls2)
816
- true
817
- else if (! ctx.explicitNulls)
815
+ else if (ctx.explicitNulls)
818
816
// If explicit nulls is enabled, we want to disallow comparison between Object and Null.
819
817
// If a nullable value has a non-nullable type, we can still cast it to nullable type
820
818
// then compare.
@@ -823,10 +821,11 @@ trait Implicits { self: Typer =>
823
821
// val x: String = null.asInstanceOf[String]
824
822
// if (x == null) {} // error: x is non-nullable
825
823
// if (x.asInstanceOf[String|Null] == null) {} // ok
826
- if (cls1 == defn.NullClass )
827
- cls2.derivesFrom(defn.ObjectClass )
828
- else
829
- cls2 == defn.NullClass && cls1.derivesFrom(defn.ObjectClass )
824
+ cls1 == defn.NullClass && cls1 == cls2
825
+ else if (cls1 == defn.NullClass )
826
+ cls1 == cls2 || cls2.derivesFrom(defn.ObjectClass )
827
+ else if (cls2 == defn.NullClass )
828
+ cls1.derivesFrom(defn.ObjectClass )
830
829
else
831
830
false
832
831
}
You can’t perform that action at this time.
0 commit comments