Skip to content

Commit

Permalink
Fix scala#21392: Adjust canComparePredefined(Nothing, T) in explici…
Browse files Browse the repository at this point in the history
…t nulls (scala#21504)

Fix scala#21392: Adjust `canComparePredefined(Nothing, T)` in explicit nulls (scala#21504)
  • Loading branch information
noti0na1 committed Aug 28, 2024
2 parents c7c5f97 + 2f9f371 commit 5e83606
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
// val x: String = null.asInstanceOf[String]
// if (x == null) {} // error: x is non-nullable
// if (x.asInstanceOf[String|Null] == null) {} // ok
cls1 == defn.NullClass && cls1 == cls2
if cls1 == defn.NullClass || cls2 == defn.NullClass then cls1 == cls2
else cls1 == defn.NothingClass || cls2 == defn.NothingClass
else if cls1 == defn.NullClass then
cls1 == cls2 || cls2.derivesFrom(defn.ObjectClass)
else if cls2 == defn.NullClass then
Expand Down
16 changes: 16 additions & 0 deletions tests/explicit-nulls/pos/i21392.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//> using options -language:strictEquality

import scala.collection.LinearSeq

def foo[T](a: LinearSeq[T]) = a match
case Nil => -1
case head +: tail => head

enum Foo derives CanEqual:
case Bar
case Baz(x: String)


def foo(a: Foo) = a match
case Foo.Bar => -1
case _ => 0

0 comments on commit 5e83606

Please sign in to comment.