-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve warning for wildcard matching only null under the explicit nulls flag (scala#21577) #21623
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.