Skip to content

Commit 2f9f371

Browse files
committed
Fix canComparePredefined(Nothing, T) in explicit nulls
1 parent e9e046d commit 2f9f371

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
187187
// val x: String = null.asInstanceOf[String]
188188
// if (x == null) {} // error: x is non-nullable
189189
// if (x.asInstanceOf[String|Null] == null) {} // ok
190-
cls1 == defn.NullClass && cls1 == cls2
190+
if cls1 == defn.NullClass || cls2 == defn.NullClass then cls1 == cls2
191+
else cls1 == defn.NothingClass || cls2 == defn.NothingClass
191192
else if cls1 == defn.NullClass then
192193
cls1 == cls2 || cls2.derivesFrom(defn.ObjectClass)
193194
else if cls2 == defn.NullClass then

Diff for: tests/explicit-nulls/pos/i21392.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//> using options -language:strictEquality
2+
3+
import scala.collection.LinearSeq
4+
5+
def foo[T](a: LinearSeq[T]) = a match
6+
case Nil => -1
7+
case head +: tail => head
8+
9+
enum Foo derives CanEqual:
10+
case Bar
11+
case Baz(x: String)
12+
13+
14+
def foo(a: Foo) = a match
15+
case Foo.Bar => -1
16+
case _ => 0

0 commit comments

Comments
 (0)