Skip to content

Commit 2a56016

Browse files
committed
Update spec
1 parent 0f761a6 commit 2a56016

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

docs/_docs/reference/experimental/erased-defs-spec.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,48 @@ nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/erased-defs
77
## Rules
88

99
1. `erased` is a soft modifier. It can appear in a `val` definition or in a parameter.
10+
* `erased` cannot appear in a `lazy` `val` definition.
11+
* `erased` _can_ appear for a parameterless given that expands to a value
12+
definition. In that case the `given` is expanded to a non-lazy `val`.
13+
* `erased` cannot appear in a mutable `var` definition.
14+
* `erased` cannot appear in an `object` definition.
1015

11-
2. A reference to an `erased` value can only be used in an *erased context*:
16+
2. Values that have a type that extends the `scala.compiletime.Erased` trait are
17+
implicitly `erased`.
18+
19+
* The restrictions of point (1) apply.
20+
* Parameterless givens are treated like values.
21+
* Mutable variables cannot have a time that extends `scala.compiletime.Erased`.
22+
23+
3. A reference to an `erased` value can only be used in an *erased context*:
1224
* Inside the expression of an argument to an `erased` parameter
1325
* Inside the body of an `erased` `val`
1426
* Inside the path of a dependent type expression
1527

16-
3. `erased` can also be used in a function type, e.g.
28+
4. `erased` can also be used in a function type, e.g.
1729

1830
* `(erased T1, T2) => R`
1931
* `(x: T1, y: erased T2) ?=> T`
2032

2133
Note that there is no subtype relation between `(erased T) => R` and `T => R` (or `(erased T) ?=> R` and `T ?=> R`). The `erased` parameters must match exactly in their respective positions.
2234

23-
4. Eta expansion
35+
5. Eta expansion
2436

2537
if `def f(erased x: T): U` then `f: (erased T) => U`.
2638

27-
5. Erasure semantics
39+
6. Erasure semantics
2840
* All `erased` parameters are removed from the function
2941
* All arguments to `erased` parameters are not passed to the function
3042
* All `erased` value definitions are removed
3143
* All `erased` argument types are removed from a function type
3244

33-
6. Overloading
45+
7. Overloading
3446

3547
Method with `erased` parameters will follow the normal overloading constraints after erasure.
3648

37-
7. Overriding
49+
8. Overriding
3850
* Member definitions overriding each other must both be `erased` or not be `erased`.
3951
* `def foo(x: T): U` cannot be overridden by `def foo(erased x: T): U` and vice-versa.
4052

41-
8. Type Restrictions
53+
9. Type Restrictions
4254
* Polymorphic function literals with erased parameters are currently not supported, and will be rejected by the compiler. This is purely an implementation restriction, and might be lifted in the future.

0 commit comments

Comments
 (0)