You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `runtimeChecked` method is an extension method, defined in `scala.Predef`. It can be called on any expression. An expression marked as `runtimeChecked` is exempt from certain static checks in the compiler, for example pattern match exhaustivity. It is intended to replace `: @unchecked` type ascription in these cases.
7
+
The `runtimeChecked` method is an extension method, defined in `scala.Predef`. It can be called on any expression. An expression ending in `.runtimeChecked` is exempt from certain static checks in the compiler, for example pattern match exhaustivity. The idiom is intended to replace a`: @unchecked` type ascription in these cases.
8
8
9
9
## Example
10
10
11
11
A common use case for `runtimeChecked` is to assert that a pattern will always match, either for convenience, or because there is a known invariant that the types can not express.
12
12
13
-
e.g. looking up an expected entry in a dynamically loaded dictionary-like structure
13
+
E.g. looking up an expected entry in a dynamically loaded dictionary-like structure:
14
14
```scala
15
15
// example 1
16
16
traitAppConfig:
@@ -35,7 +35,7 @@ weekDay.runtimeChecked match
35
35
caseNone=>
36
36
```
37
37
38
-
In both of these cases, without `runtimeChecked`then there would either be an error (example 1), or a warning (example 2), because statically, the compiler knows that there could be other cases at runtime - so is right to caution the programmer.
38
+
In both of these cases, without `runtimeChecked` there would either be an error (example 1), or a warning (example 2), because statically, the compiler knows that there could be other cases at runtime - so is right to caution the programmer.
39
39
40
40
```scala
41
41
// warning in example 2 when we don't add `.runtimeChecked`.
@@ -76,18 +76,18 @@ val res1: Int = 1
76
76
77
77
## Specification
78
78
79
-
We add a new annotation `scala.internal.RuntimeChecked`, this is part of the standard Scala 3 library. A programmer is not expected to use this annotation directly.
79
+
We add a new annotation `scala.internal.RuntimeChecked` as a part of the standard Scala 3 library. A programmer is not expected to use this annotation directly.
80
80
81
81
```scala
82
82
packagescala.annotation.internal
83
83
84
84
finalclassRuntimeCheckedextendsAnnotation
85
85
```
86
86
87
-
Any term that is the scrutinee of a pattern match, that has a type annotated with `RuntimeChecked`, is exempt from pattern match exhaustivity checking.
87
+
Any term that is the scrutinee of a pattern match, and that has a type annotated with `RuntimeChecked`, is exempt from pattern match exhaustivity checking.
88
88
89
89
90
-
The user facing API is provided by a new extension method `scala.Predef.runtimeChecked`, qualified for any value:
90
+
The user facing API is augmented with a new extension method `scala.Predef.runtimeChecked`, qualified for any value:
91
91
```scala
92
92
packagescala
93
93
@@ -124,9 +124,9 @@ As an escape hatch in 3.2 we recommended to use a type ascription of `: @uncheck
124
124
|which may result in a MatchError at runtime.
125
125
```
126
126
127
-
We suggest that `: @unchecked` is syntactically awkward, and also a misnomer - in fact in this case the the pattern is fully checked, but the necessary checks occur at runtime. The `runtimeChecked` method is then a successor to `@unchecked` for this purpose.
127
+
However, `: @unchecked` is syntactically awkward, and is also a misnomer - in fact in this case the the pattern _is_ fully checked, but the necessary checks occur at runtime. The `runtimeChecked` method is intended to replace `@unchecked` for this purpose.
128
128
129
-
We propose that `@unchecked`will still be necessary for silencing warnings on unsound type tests.
129
+
The `@unchecked`annotation is still retained for silencing warnings on unsound type tests.
130
130
131
131
### Restoring Scala 2.13 semantics with runtimeChecked
0 commit comments