-
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.
Improve warning for wildcard matching only null under the explicit nu…
…lls flag (#21577) (#21623) Improve warning for wildcard matching only null under the explicit nulls. Fix #21577
- Loading branch information
Showing
8 changed files
with
130 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:5:9 -------------------------------------------- | ||
5 | case _ => // warn | ||
| ^ | ||
| Unreachable case except for null (if this is intentional, consider writing case null => instead). | ||
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:12:9 ------------------------------------------- | ||
12 | case _ => // warn | ||
| ^ | ||
| Unreachable case except for null (if this is intentional, consider writing case null => instead). | ||
-- [E030] Match case Unreachable Warning: tests/explicit-nulls/warn/i21577.scala:20:7 ---------------------------------- | ||
20 | case _ => // warn | ||
| ^ | ||
| Unreachable case | ||
-- [E029] Pattern Match Exhaustivity Warning: tests/explicit-nulls/warn/i21577.scala:29:27 ----------------------------- | ||
29 |def f7(s: String | Null) = s match // warn | ||
| ^ | ||
| match may not be exhaustive. | ||
| | ||
| It would fail on pattern case: _: Null | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E029] Pattern Match Exhaustivity Warning: tests/explicit-nulls/warn/i21577.scala:36:33 ----------------------------- | ||
36 |def f9(s: String | Int | Null) = s match // warn | ||
| ^ | ||
| match may not be exhaustive. | ||
| | ||
| It would fail on pattern case: _: Int | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,38 @@ | ||
def f(s: String) = | ||
val s2 = s.trim() | ||
s2 match | ||
case s3: String => | ||
case _ => // warn | ||
|
||
|
||
def f2(s: String | Null) = | ||
val s2 = s.nn.trim() | ||
s2 match | ||
case s3: String => | ||
case _ => // warn | ||
|
||
def f3(s: String | Null) = s match | ||
case s2: String => | ||
case _ => | ||
|
||
def f5(s: String) = s match | ||
case _: String => | ||
case _ => // warn | ||
|
||
def f6(s: String) = s.trim() match | ||
case _: String => | ||
case null => | ||
|
||
def f61(s: String) = s.trim() match | ||
case _: String => | ||
|
||
def f7(s: String | Null) = s match // warn | ||
case _: String => | ||
|
||
def f8(s: String | Null) = s match | ||
case _: String => | ||
case null => | ||
|
||
def f9(s: String | Int | Null) = s match // warn | ||
case _: String => | ||
case null => |
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,8 @@ | ||
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/interop/S.scala:8:11 ---------------------------------------- | ||
8 | case _ => // warn | ||
| ^ | ||
| Unreachable case except for null (if this is intentional, consider writing case null => instead). | ||
-- [E121] Pattern Match Warning: tests/explicit-nulls/warn/interop/S.scala:9:9 ----------------------------------------- | ||
9 | case _ => println(2) // warn | ||
| ^ | ||
| 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,6 @@ | ||
import java.util.ArrayList; | ||
|
||
class J { | ||
ArrayList<ArrayList<String>> foo(String x) { return null; } | ||
static String fooStatic(String x) { return null; } | ||
} |
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,10 @@ | ||
import java.util.ArrayList | ||
def f() = | ||
val j = new J() | ||
val s2 = j.foo(null) | ||
s2 match | ||
case s3: ArrayList[ArrayList[String]] => s3.get(0) match | ||
case _: ArrayList[_] => | ||
case _ => // warn | ||
case _ => println(2) // warn | ||
|