-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix warning message for matching on redundant nulls (#21850)
- Loading branch information
Showing
11 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
6: Match case Unreachable | ||
14: Match case Unreachable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
6: Pattern Match | ||
6: Match case Unreachable | ||
13: Pattern Match | ||
18: Match case Unreachable | ||
20: Pattern Match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:10:7 ----------------------------------------- | ||
10 | case _: n.type => // warn: unreachable | ||
| ^^^^^^^^^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:12:7 ----------------------------------------- | ||
12 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:13:7 ----------------------------------------- | ||
13 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:18:7 ----------------------------------------- | ||
18 | case _ => 3 // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:23:7 ----------------------------------------- | ||
23 | case _: B => // warn: unreachable | ||
| ^^^^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:24:7 ----------------------------------------- | ||
24 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:25:7 ----------------------------------------- | ||
25 | case null => // warn: unreachable | ||
| ^^^^ | ||
| Unreachable case | ||
-- [E121] Pattern Match Warning: tests/warn/redundant-null.scala:30:7 -------------------------------------------------- | ||
30 | case _ => // warn: null only | ||
| ^ | ||
| Unreachable case except for null (if this is intentional, consider writing case null => instead). | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:31:7 ----------------------------------------- | ||
31 | case null => // warn: unreachable | ||
| ^^^^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:32:7 ----------------------------------------- | ||
32 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:33:7 ----------------------------------------- | ||
33 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:37:7 ----------------------------------------- | ||
37 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E030] Match case Unreachable Warning: tests/warn/redundant-null.scala:41:7 ----------------------------------------- | ||
41 | case _ => // warn: unreachable | ||
| ^ | ||
| Unreachable case | ||
-- [E121] Pattern Match Warning: tests/warn/redundant-null.scala:45:7 -------------------------------------------------- | ||
45 | case _ => // warn: null only | ||
| ^ | ||
| Unreachable case except for null (if this is intentional, consider writing case null => instead). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class A | ||
class B | ||
class C | ||
|
||
val n = null | ||
|
||
def f(s: A) = s match | ||
case _: n.type => | ||
case _: A => | ||
case _: n.type => // warn: unreachable | ||
case null => | ||
case _ => // warn: unreachable | ||
case _ => // warn: unreachable | ||
|
||
def f2(s: A | B | C) = s match | ||
case _: A => 0 | ||
case _: C | null | _: B => 1 | ||
case _ => 3 // warn: unreachable | ||
|
||
def f3(s: A | B) = s match | ||
case _: A => | ||
case _ => | ||
case _: B => // warn: unreachable | ||
case _ => // warn: unreachable | ||
case null => // warn: unreachable | ||
|
||
def f4(s: String | Int) = s match | ||
case _: Int => | ||
case _: String => | ||
case _ => // warn: null only | ||
case null => // warn: unreachable | ||
case _ => // warn: unreachable | ||
case _ => // warn: unreachable | ||
|
||
def f5(x: String) = x match | ||
case x => | ||
case _ => // warn: unreachable | ||
|
||
def test(s: String | Null) = s match | ||
case ss => | ||
case _ => // warn: unreachable | ||
|
||
def test2(s: String | Null) = s match | ||
case ss: String => | ||
case _ => // warn: null only |