Skip to content

Commit c878878

Browse files
committed
Update doc pages
1 parent ea93df5 commit c878878

File tree

5 files changed

+192
-219
lines changed

5 files changed

+192
-219
lines changed

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

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,38 @@ title: "Erased Definitions - More Details"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/erased-defs-spec.html
55
---
66

7-
TODO: complete
87
## Rules
98

10-
1. `erased` is a soft modifier. It can appear:
11-
* At the start of a parameter block of a method, function or class
12-
* In a method definition
13-
* In a `val` definition (but not `lazy val` or `var`)
14-
* In a `class` or `trait` definition
9+
1. `erased` is a soft modifier. It can appear in a `val` definition or in a parameter.
1510

16-
```scala
17-
erased val x = ...
18-
erased def f = ...
19-
20-
def g(erased x: Int) = ...
21-
22-
(erased x: Int, y: Int) => ...
23-
def h(x: (Int, erased Int) => Int) = ...
24-
25-
class K(erased x: Int) { ... }
26-
erased class E {}
27-
```
28-
29-
30-
2. A reference to an `erased` val or def can only be used
11+
2. A reference to an `erased` value can only be used
3112
* Inside the expression of argument to an `erased` parameter
3213
* Inside the body of an `erased` `val` or `def`
3314

15+
3. `erased` can also be used in a function type, e.g.
3416

35-
3. Functions
36-
* `(erased x1: T1, x2: T2, ..., xN: TN) => y : (erased T1, T2, ..., TN) => R`
37-
* `(using x1: T1, erased x2: T2, ..., xN: TN) => y: (using T1, erased T2, ..., TN) => R`
38-
* `(using erased T1) => R <:< erased T1 => R`
39-
* `(using T1, erased T2) => R <:< (T1, erased T2) => R`
40-
* ...
41-
42-
Note that there is no subtype relation between `(erased T) => R` and `T => R` (or `(given erased T) => R` and `(given T) => R`). The `erased` parameters must match exactly in their respective positions.
17+
* `(erased T1, T2) => R`
18+
* `(x: T1, y: erased T2) ?=> T`
4319

20+
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.
4421

4522
4. Eta expansion
4623

4724
if `def f(erased x: T): U` then `f: (erased T) => U`.
4825

49-
5026
5. Erasure semantics
5127
* All `erased` parameters are removed from the function
5228
* All argument to `erased` parameters are not passed to the function
53-
* All `erased` definitions are removed
54-
* `(erased ET1, erased ET2, T1, ..., erased ETN, TM) => R` are erased to `(T1, ..., TM) => R`.
55-
* `(given erased ET1, erased ET2, T1, ..., erased ETN, TM) => R` are erased to `(given T1, ..., TM) => R`.
56-
29+
* All `erased` value definitions are removed
30+
* All `erased` argument types are removed from a function type
5731

5832
6. Overloading
5933

6034
Method with `erased` parameters will follow the normal overloading constraints after erasure.
6135

62-
6336
7. Overriding
6437
* Member definitions overriding each other must both be `erased` or not be `erased`.
6538
* `def foo(x: T): U` cannot be overridden by `def foo(erased x: T): U` and vice-versa.
6639

6740
8. Type Restrictions
68-
* For dependent functions, `erased` parameters are limited to realizable types, that is, types that are inhabited by non-null values.
69-
This restriction stops us from using a bad bound introduced by an erased value, which leads to unsoundness (see #4060).
7041
* Polymorphic functions 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)