Skip to content

Commit fc54f16

Browse files
bishaboshaodersky
andauthored
Apply suggestions from code review
improve documentation based on suggestions Co-authored-by: odersky <odersky@gmail.com>
1 parent d29ec53 commit fc54f16

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/_docs/reference/experimental/runtimeChecked.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: "The runtimeChecked method"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/runtimeChecked.html
55
---
66

7-
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.
88

99
## Example
1010

1111
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.
1212

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:
1414
```scala
1515
// example 1
1616
trait AppConfig:
@@ -35,7 +35,7 @@ weekDay.runtimeChecked match
3535
case None =>
3636
```
3737

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.
3939

4040
```scala
4141
// warning in example 2 when we don't add `.runtimeChecked`.
@@ -76,18 +76,18 @@ val res1: Int = 1
7676

7777
## Specification
7878

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.
8080

8181
```scala
8282
package scala.annotation.internal
8383

8484
final class RuntimeChecked extends Annotation
8585
```
8686

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.
8888

8989

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:
9191
```scala
9292
package scala
9393

@@ -124,9 +124,9 @@ As an escape hatch in 3.2 we recommended to use a type ascription of `: @uncheck
124124
|which may result in a MatchError at runtime.
125125
```
126126

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.
128128

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.
130130

131131
### Restoring Scala 2.13 semantics with runtimeChecked
132132

0 commit comments

Comments
 (0)