Skip to content

Fix case null on non-nullable type in unsafe nulls #13976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add patman test
  • Loading branch information
noti0na1 committed Jan 31, 2022
commit 60d7781b5f35c3fd802e6dd34c4e9d6c859b5aef
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class Foo {

val s: String = ???
s match {
case s: String => 100 // warning: type test will always succeed
case _ => 200 // error: unreachable
}

s match {
case s: String => 100 // warning: type test will always succeed
case s: String => 100
case _ => 200 // error: unreachable
}

Expand All @@ -15,20 +12,23 @@ class Foo {
case object Cat extends Animal

val a: Animal = ???

a match {
case Dog(name) => 100
case Cat => 200
case _ => 300 // error: unreachable
}

val a2: Animal|Null = ???
val a2: Animal | Null = ???

a2 match {
case Dog(_) => 100
case Cat => 200
case _ => 300
}

val a3: Animal|Null = ???
val a3: Animal | Null = ???

a3 match {
case Dog(_) => 100
case Cat => 200
Expand Down
14 changes: 14 additions & 0 deletions tests/explicit-nulls/neg-patmat/unsafe-match-null-pat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.language.unsafeNulls

def test1 =
val s: String = ???
s match
case _: String =>
// under unsafeNulls, we should not get Match case Unreachable Warning
case null => // ok

def test2 =
val s: String | Null = ???
s match
case _: String =>
case null =>
3 changes: 1 addition & 2 deletions tests/explicit-nulls/unsafe-common/unsafe-match-null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ def test1 =
val s: String = ???
s match
case _: String =>
// under unsafeNulls, we should not get Match case Unreachable Warning
case null => // error
case null => // error: Values of types Null and String cannot be compared

def test2 =
val s: String | Null = ???
Expand Down