-
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.
add method, annotation and test cases
- Loading branch information
1 parent
594306d
commit 5cb3301
Showing
10 changed files
with
92 additions
and
4 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
11 changes: 11 additions & 0 deletions
11
library/src/scala/annotation/internal/RuntimeChecked.scala
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 @@ | ||
package scala.annotation.internal | ||
|
||
import scala.annotation.Annotation | ||
import scala.annotation.experimental | ||
|
||
/**An annotation marking an intention that all checks on a value can be reliably performed at runtime. | ||
* | ||
* The compiler will remove certain static checks except those that can't be performed at runtime. | ||
*/ | ||
@experimental | ||
final class RuntimeChecked() extends 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
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,5 @@ | ||
-- [E030] Match case Unreachable Warning: tests/neg/runtimeChecked-2.scala:13:11 --------------------------------------- | ||
13 | case is: Some[t] => ??? // unreachable | ||
| ^^^^^^^^^^^ | ||
| Unreachable case | ||
No warnings can be incurred under -Werror (or -Xfatal-warnings) |
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,16 @@ | ||
//> using options -Werror -source:future | ||
|
||
import annotation.experimental | ||
|
||
@experimental | ||
object Foo { | ||
|
||
val xs: Option[Int] = Some(1) | ||
|
||
def test: Int = | ||
xs.runtimeChecked match { // this test asserts that reachability is not avoided by runtimeChecked | ||
case is: Some[t] => is.get | ||
case is: Some[t] => ??? // unreachable | ||
} | ||
} | ||
// nopos-error: No warnings can be incurred under -Werror (or -Xfatal-warnings) |
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 @@ | ||
-- [E092] Pattern Match Unchecked Warning: tests/neg/runtimeChecked.scala:14:11 ---------------------------------------- | ||
14 | case is: ::[Int/* can not be checked so still err */] => is.head | ||
| ^ | ||
|the type test for ::[Int] cannot be checked at runtime because its type arguments can't be determined from List[Any] | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
No warnings can be incurred under -Werror (or -Xfatal-warnings) |
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,17 @@ | ||
//> using options -Werror -source:future | ||
|
||
import annotation.experimental | ||
|
||
@experimental | ||
object Foo { | ||
|
||
val xs: List[Any] = List(1: Any) | ||
|
||
def test: Int = | ||
xs.runtimeChecked match { // this test asserts that unsound type tests still require @unchecked | ||
// tests/run/runtimeChecked.scala adds @unchecked to the | ||
// unsound type test to avoid the warning. | ||
case is: ::[Int/* can not be checked so still err */] => is.head | ||
} | ||
} | ||
// nopos-error: No warnings can be incurred under -Werror (or -Xfatal-warnings) |
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,16 @@ | ||
//> using options -Werror -source:future | ||
|
||
import annotation.experimental | ||
|
||
|
||
val xs: List[Any] = List(1: Any) | ||
|
||
@experimental | ||
@main | ||
def Test: Unit = | ||
val head = xs.runtimeChecked match { | ||
// tests/neg/runtimeChecked.scala asserts that @unchecked is | ||
// still needed for unsound type tests. | ||
case is: ::[Int @unchecked] => is.head | ||
} | ||
assert(head == 1) |