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
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/context-functions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,7 +112,7 @@ With that setup, the table construction code above compiles and expands to:
112
112
```
113
113
### Example: Postconditions
114
114
115
-
As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring` so that the checked result can be referred to simply by `result`. The example combines opaque aliases, context function types, and extension methods to provide a zero-overhead abstraction.
115
+
As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring` so that the checked result can be referred to simply by `result`. The example combines opaque type aliases, context function types, and extension methods to provide a zero-overhead abstraction.
Copy file name to clipboardExpand all lines: docs/docs/reference/dropped-features/package-objects.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ The compiler generates synthetic objects that wrap toplevel definitions falling
31
31
32
32
- all pattern, value, method, and type definitions,
33
33
- implicit classes and objects,
34
-
- companion objects of opaque types.
34
+
- companion objects of opaque type aliases.
35
35
36
36
If a source file `src.scala` contains such toplevel definitions, they will be put in a synthetic object named `src$package`. The wrapping is transparent, however. The definitions in `src` can still be accessed as members of the enclosing package.
Copy file name to clipboardExpand all lines: docs/docs/reference/enums/desugarEnums.md
+24-23Lines changed: 24 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,33 +19,34 @@ some terminology and notational conventions:
19
19
20
20
-_Class cases_ are those cases that are parameterized, either with a type parameter section `[...]` or with one or more (possibly empty) parameter sections `(...)`.
21
21
-_Simple cases_ are cases of a non-generic enum that have neither parameters nor an extends clause or body. That is, they consist of a name only.
22
-
-_Value cases_ are all cases that do not have a parameter section but that do have a (possibly generated) extends clause and/or a body.
22
+
-_Value cases_ are all cases that do not have a parameter section but that do have a (possibly generated) `extends` clause and/or a body.
23
23
24
24
Simple cases and value cases are collectively called _singleton cases_.
25
25
26
26
The desugaring rules imply that class cases are mapped to case classes, and singleton cases are mapped to `val` definitions.
27
27
28
28
There are nine desugaring rules. Rule (1) desugar enum definitions. Rules
29
-
(2) and (3) desugar simple cases. Rules (4) to (6) define extends clauses for cases that
30
-
are missing them. Rules (7) to (9) define how such cases with extends clauses
31
-
map into case classes or vals.
32
-
33
-
1.An `enum` definition
34
-
```scala
35
-
enumE ... { <defs> <cases> }
36
-
```
37
-
expands to a `sealed` `abstract` classthatextends the `scala.Enum` traitand
38
-
an associated companion objectthat contains the defined cases, expanded according
39
-
to rules (2-8). Theenumtrait starts with a compiler-generated importthatimports
40
-
the names `<caseIds>` of all cases so that they can be used without prefix in the trait.
41
-
```scala
42
-
sealedabstractclassE ... extends <parents> with scala.Enum {
43
-
importE.{ <caseIds> }
29
+
(2) and (3) desugar simple cases. Rules (4) to (6) define `extends` clauses for cases that
30
+
are missing them. Rules (7) to (9) define how such cases with `extends` clauses
31
+
map into `case class`es or `val`s.
32
+
33
+
1. An `enum` definition
34
+
```scala
35
+
enumE ... { <defs> <cases> }
36
+
```
37
+
expands to a `sealedabstract` class that extends the `scala.Enum` trait and
38
+
an associated companion object that contains the defined cases, expanded according
39
+
to rules (2 - 8). The enum trait starts with a compiler-generated import that imports
40
+
the names `<caseIds>` of all cases so that they can be used without prefix in the trait.
41
+
```scala
42
+
sealedabstractclassE ... extends <parents> with scala.Enum {
43
+
importE.{ <caseIds> }
44
44
<defs>
45
-
}
46
-
objectE { <cases> }
47
-
```
48
-
2. A simple case consisting of a comma-separated list of enumnames
45
+
}
46
+
objectE { <cases> }
47
+
```
48
+
49
+
2. A simple case consisting of a comma-separated list of enum names
49
50
```scala
50
51
caseC_1, ..., C_n
51
52
```
@@ -69,7 +70,7 @@ map into case classes or vals.
69
70
70
71
4. If `E` is an enum with type parameters
71
72
```scala
72
-
V1T1>L1<:U1 , ... , VnTn>:Ln<:Un (n >0)
73
+
V1T1>:L1<:U1 , ... , VnTn>:Ln<:Un (n >0)
73
74
```
74
75
where each of the variances `Vi` is either `'+'` or `'-'`, then a simple case
75
76
```scala
@@ -81,7 +82,7 @@ map into case classes or vals.
81
82
```
82
83
where `Bi` is `Li` if `Vi = '+'` and `Ui` if `Vi = '-'`. This result is then further
83
84
rewritten with rule (8). Simple cases of enums with non-variant type
84
-
parameters are not permitted.
85
+
parameters are not permitted (however value cases with explicit `extends` clause are)
85
86
86
87
5. A class case without an extends clause
87
88
```scala
@@ -201,4 +202,4 @@ Cases such as `case C` expand to a `@static val` as opposed to a `val`. This all
201
202
explicitly declared in it.
202
203
203
204
-If an enumcase has an extends clause, the enumclass must be one of the
@@ -124,17 +124,21 @@ The third rule states that a match type conforms to its upper bound
124
124
125
125
Within a match type `Match(S, Cs) <: B`, all occurrences of type variables count as covariant. By the nature of the cases `Ci` this means that occurrences in pattern position are contravarant (since patterns are represented as function type arguments).
126
126
127
-
## Typing Rules for Match Expressions
127
+
<!-- TODO revise this section, at least `S` has to be invariant according to the current implementation -->
128
+
129
+
## Typing Rules for Match Expressions (Work in Progress)
130
+
131
+
<!-- TODO document the final solution and remove (Work in Progress) -->
128
132
129
133
Typing rules for match expressions are tricky. First, they need some new form of GADT matching for value parameters.
130
134
Second, they have to account for the difference between sequential match on the term level and parallel match on the type level. As a running example consider:
131
135
```scala
132
-
typeM[+X] =Xmatch {
136
+
typeM[X] =Xmatch {
133
137
caseA=>1
134
138
caseB=>2
135
139
}
136
140
```
137
-
We'd like to be able to typecheck
141
+
We would like to be able to typecheck
138
142
```scala
139
143
defm[X](x: X):M[X] = x match {
140
144
case_: A=>1// type error
@@ -144,14 +148,14 @@ def m[X](x: X): M[X] = x match {
144
148
Unfortunately, this goes nowhere. Let's try the first case. We have: `x.type <: A` and `x.type <: X`. This tells
145
149
us nothing useful about `X`, so we cannot reduce `M` in order to show that the right hand side of the case is valid.
146
150
147
-
The following variant is more promising:
151
+
The following variant is more promising but does not compile either:
148
152
```scala
149
153
defm(x: Any):M[x.type] = x match {
150
154
case_: A=>1
151
155
case_: B=>2
152
156
}
153
157
```
154
-
To make this work, we'd need a new form of GADT checking: If the scrutinee is a term variable `s`, we can make use of
158
+
To make this work, we would need a new form of GADT checking: If the scrutinee is a term variable `s`, we can make use of
155
159
the fact that `s.type` must conform to the pattern's type and derive a GADT constraint from that. For the first case above,
156
160
this would be the constraint `x.type <: A`. The new aspect here is that we need GADT constraints over singleton types where
157
161
before we just had constraints over type parameters.
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/control-syntax.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,4 +39,4 @@ The rules in detail are:
39
39
### Rewrites
40
40
41
41
The Dotty compiler can rewrite source code from old syntax and new syntax and back.
42
-
When invoked with options `-rewrite -new-syntax` it will rewrite from old to new syntax, dropping parentheses and braces in conditions and enumerators. When invoked with with options `-rewrite -old-syntax` it will rewrite in the reverse direction, inserting parentheses and braces as needed.
42
+
When invoked with options `-rewrite -new-syntax` it will rewrite from old to new syntax, dropping parentheses and braces in conditions and enumerators. When invoked with options `-rewrite -old-syntax` it will rewrite in the reverse direction, inserting parentheses and braces as needed.
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/explicit-nulls.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,13 +17,13 @@ Instead, to mark a type as nullable we use a [type union](https://dotty.epfl.ch/
17
17
val x: String|Null = null // ok
18
18
```
19
19
20
-
Explicit nulls are enabled via a `-Yexplicit-nulls` flag, so they're an opt-in feature.
20
+
Explicit nulls are enabled via a `-Yexplicit-nulls` flag.
21
21
22
22
Read on for details.
23
23
24
24
## New Type Hierarchy
25
25
26
-
When explicit nulls are enabled, the type hierarchy changes so that `Null` is subtype only of
26
+
When explicit nulls are enabled, the type hierarchy changes so that `Null` is only a subtype of
27
27
`Any`, as opposed to every reference type.
28
28
29
29
This is the new type hierarchy:
@@ -33,7 +33,7 @@ After erasure, `Null` remains a subtype of all reference types (as forced by the
33
33
34
34
## Unsoundness
35
35
36
-
The new type system is unsound with respect to `null`. This means there are still instances where an expressions has a non-nullable type like `String`, but its value is `null`.
36
+
The new type system is unsound with respect to `null`. This means there are still instances where an expression has a non-nullable type like `String`, but its value is actually`null`.
37
37
38
38
The unsoundness happens because uninitialized fields in a class start out as `null`:
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/opaques-details.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,22 +20,22 @@ The general form of a (monomorphic) opaque type alias is
20
20
```scala
21
21
opaquetypeT>:L<:U=R
22
22
```
23
-
where the lower bound `L` and the upper bound `U` may be missing, in which case they are assumed to be `scala.Nothing` and `scala.Any`, respectively. If bounds are given, it is checked that the right hand side `R` conforms to them, i.e. `L <: R` and `R <: U`. F-bounds are not supported for opaque types: `T` is not allowed to appear in `L` or `U`.
23
+
where the lower bound `L` and the upper bound `U` may be missing, in which case they are assumed to be `scala.Nothing` and `scala.Any`, respectively. If bounds are given, it is checked that the right hand side `R` conforms to them, i.e. `L <: R` and `R <: U`. F-bounds are not supported for opaque type aliases: `T` is not allowed to appear in `L` or `U`.
24
24
25
25
Inside the scope of the alias definition, the alias is transparent: `T` is treated
26
26
as a normal alias of `R`. Outside its scope, the alias is treated as the abstract type
27
27
```scala
28
28
typeT>:L<:U
29
29
```
30
-
A special case arises if the opaque type is defined in an object. Example:
30
+
A special case arises if the opaque type alias is defined in an object. Example:
31
31
```
32
32
object o {
33
33
opaque type T = R
34
34
}
35
35
```
36
36
In this case we have inside the object (also for non-opaque types) that `o.T` is equal to
37
37
`T` or its expanded form `o.this.T`. Equality is understood here as mutual subtyping, i.e.
38
-
`o.T <: o.this.T` and `o.this.T <: T`. Furthermore, we have by the rules of opaque types
38
+
`o.T <: o.this.T` and `o.this.T <: T`. Furthermore, we have by the rules of opaque type aliases
39
39
that `o.this.T` equals `R`. The two equalities compose. That is, inside `o`, it is
40
40
also known that `o.T` is equal to `R`. This means the following code type-checks:
41
41
```scala
@@ -48,7 +48,7 @@ def id(x: o.T): o.T = x
48
48
49
49
### Toplevel Opaque Types
50
50
51
-
An opaque type on the toplevel is transparent in all other toplevel definitions in the sourcefile where it appears, but is opaque in nested
51
+
An opaque type alias on the toplevel is transparent in all other toplevel definitions in the sourcefile where it appears, but is opaque in nested
52
52
objects and classes and in all other source files. Example:
53
53
```scala
54
54
// in test1.scala
@@ -69,10 +69,10 @@ object test1$package {
69
69
valx:A="abc"
70
70
}
71
71
objectobj {
72
-
valy:A="abc"// error: cannot assign "abc" to opaque type A
72
+
valy:A="abc"// error: cannot assign "abc" to opaque type alias A
73
73
}
74
74
```
75
-
The opaque type `A` is transparent in its scope, which includes the definition of `x`, but not the definitions of `obj` and `y`.
75
+
The opaque type alias `A` is transparent in its scope, which includes the definition of `x`, but not the definitions of `obj` and `y`.
0 commit comments