Skip to content

Commit

Permalink
Backport "Fix #21392: Adjust canComparePredefined(Nothing, T) in ex…
Browse files Browse the repository at this point in the history
…plicit nulls" to LTS (#22113)

Backports #21504 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Dec 4, 2024
2 parents 52a6878 + 9482449 commit a83ec78
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 @@ -186,7 +186,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 a83ec78

Please sign in to comment.