-
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.
Warn about unchecked type tests in primitive catch cases
- Loading branch information
1 parent
a3854cb
commit 7879bfe
Showing
11 changed files
with
72 additions
and
8 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
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,9 @@ | ||
//> using options -Xfatal-warnings | ||
|
||
def handle[E <: Exception](f: => Unit): Option[E] = | ||
try | ||
f | ||
None | ||
catch case e: E @unchecked => Some(e) | ||
|
||
val r: RuntimeException = handle[RuntimeException](throw new Exception()).get |
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,11 @@ | ||
//> using options -Xfatal-warnings | ||
|
||
case class CustomException(x: Any) extends Exception("") | ||
|
||
def handle[E](f: => Unit): Option[E] = | ||
try | ||
f | ||
None | ||
catch case CustomException(e: E @unchecked ) => Some(e) | ||
|
||
val r: RuntimeException = handle[RuntimeException](throw new Exception()).get |
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 @@ | ||
-- [E092] Pattern Match Unchecked Warning: tests/warn/i19013-a.scala:5:13 ---------------------------------------------- | ||
5 | catch case e: E => Some(e) // warn | ||
| ^^^^ | ||
| the type test for E cannot be checked at runtime because it refers to an abstract type member or type parameter | ||
| | ||
| 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,7 @@ | ||
def handle[E <: Exception](f: => Unit): Option[E] = | ||
try | ||
f | ||
None | ||
catch case e: E => Some(e) // warn | ||
|
||
val r: RuntimeException = handle[RuntimeException](throw new Exception()).get |
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 @@ | ||
-- [E092] Pattern Match Unchecked Warning: tests/warn/i19013-b.scala:7:29 ---------------------------------------------- | ||
7 | catch case CustomException(e: E) => Some(e) // warn | ||
| ^ | ||
| the type test for E cannot be checked at runtime because it refers to an abstract type member or type parameter | ||
| | ||
| 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,9 @@ | ||
case class CustomException(x: Any) extends Exception("") | ||
|
||
def handle[E](f: => Unit): Option[E] = | ||
try | ||
f | ||
None | ||
catch case CustomException(e: E) => Some(e) // warn | ||
|
||
val r: RuntimeException = handle[RuntimeException](throw new Exception()).get |