File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 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 =>
812812 cmpWithBoxed(cls1, cls2)
813813 else if (cls2.isPrimitiveValueClass)
814814 cmpWithBoxed(cls2, cls1)
815- else if (cls1 == defn.NullClass && cls1 == cls2)
816- true
817- else if (! ctx.explicitNulls)
815+ else if (ctx.explicitNulls)
818816 // If explicit nulls is enabled, we want to disallow comparison between Object and Null.
819817 // If a nullable value has a non-nullable type, we can still cast it to nullable type
820818 // then compare.
@@ -823,10 +821,11 @@ trait Implicits { self: Typer =>
823821 // val x: String = null.asInstanceOf[String]
824822 // if (x == null) {} // error: x is non-nullable
825823 // 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 )
830829 else
831830 false
832831 }
You can’t perform that action at this time.
0 commit comments