Skip to content

Commit

Permalink
Fix canComparePredefined(Nothing, T) in explicit nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Aug 28, 2024
1 parent e9e046d commit 2f9f371
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 2f9f371

Please sign in to comment.