-
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 non-nullable types (#21577)
Adds a more detailed warning message when a wildcard case is unreachable on an non-nullable type to suggest adding a nullable type annotation. Fixes #21577
- Loading branch information
Showing
6 changed files
with
49 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- [E202] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:5:9 -------------------------------------------- | ||
5 | case _ => println(2) // warn | ||
| ^ | ||
| Unreachable case (if expression is expected to be nullable, consider giving it a nullable type annotation). | ||
-- [E202] Pattern Match Warning: tests/explicit-nulls/warn/i21577.scala:12:11 ------------------------------------------ | ||
12 | case _ => println(2) // warn | ||
| ^ | ||
| Unreachable case (if expression is expected to be nullable, consider giving it a nullable type annotation). |
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,24 @@ | ||
def f(s: String) = | ||
val s2 = s.trim() | ||
s2 match | ||
case s3: String => println(1) | ||
case _ => println(2) // warn | ||
|
||
|
||
def f2(s: String | Null) = | ||
val s2 = s.nn.trim() | ||
s2 match | ||
case s3: String => println(1) | ||
case _ => println(2) // warn | ||
|
||
def f3(s: String | Null) = | ||
val s2 = s | ||
s2 match | ||
case s3: String => println(1) | ||
case _ => println(2) | ||
|
||
def f4(s: String | Int) = | ||
val s2 = s | ||
s2 match | ||
case s3: String => println(1) | ||
case _ => println(2) |