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
Spec: Refactoring: Merge "definitions" and "declarations".
Previously, abstract members were syntactically separate from
concrete members, and referred to "declarations", as opposed to
"definitions".
In this commit, all of them become "definitions". There are
abstract definitions and concrete definitions. They share their
syntactic productions.
This will allow to more easily introduce more kinds of definitions
that can be abstract or concrete in deeper productions of the
grammar, such as extension methods.
Copy file name to clipboardExpand all lines: docs/_spec/01-lexical-syntax.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -218,13 +218,13 @@ Multiple newline tokens are accepted in the following places (note that a semico
218
218
219
219
- between the condition of a [conditional expression](06-expressions.html#conditional-expressions) or [while loop](06-expressions.html#while-loop-expressions) and the next following expression,
220
220
- between the enumerators of a [for-comprehension](06-expressions.html#for-comprehensions-and-for-loops) and the next following expression, and
221
-
- after the initial `type` keyword in a [type definition or declaration](04-basic-declarations-and-definitions.html#type-declarations-and-type-aliases).
221
+
- after the initial `type` keyword in a [type definition](04-basic-definitions.html#type-member-definitions).
222
222
223
223
A single new line token is accepted
224
224
225
225
- in front of an opening brace ‘{’, if that brace is a legal continuation of the current statement or expression,
226
226
- after an [infix operator](06-expressions.html#prefix,-infix,-and-postfix-operations), if the first token on the next line can start an expression,
227
-
- in front of a [parameter clause](04-basic-declarations-and-definitions.html#function-declarations-and-definitions), and
227
+
- in front of a [parameter clause](04-basic-definitions.html#method-definitions), and
228
228
- after an [annotation](11-annotations.html#user-defined-annotations).
229
229
230
230
> The newline tokens between the two lines are not treated as statement separators.
Bindings of different kinds have precedence defined on them:
18
18
19
-
1. Definitions and declarations that are local, inherited, or made available by a package clause and also defined in the same compilation unit as the reference to them, have the highest precedence.
19
+
1. Definitions that are local, inherited, or made available by a package clause and also defined in the same compilation unit as the reference to them, have the highest precedence.
20
20
1. Explicit imports have the next highest precedence.
21
21
1. Wildcard imports have the next highest precedence.
22
22
1. Definitions made available by a package clause, but not also defined in the same compilation unit as the reference to them, as well as imports which are supplied by the compiler but not explicitly written in source code, have the lowest precedence.
@@ -48,7 +48,7 @@ A reference to an unqualified (type- or term-) identifier ´x´ is bound by the
48
48
49
49
It is an error if no such binding exists.
50
50
If ´x´ is bound by an import clause, then the simple name ´x´ is taken to be equivalent to the qualified name to which ´x´ is mapped by the import clause.
51
-
If ´x´ is bound by a definition or declaration, then ´x´ refers to the entity introduced by that binding.
51
+
If ´x´ is bound by a definition, then ´x´ refers to the entity introduced by that binding.
52
52
In that case, the type of ´x´ is the type of the referenced entity.
53
53
54
54
A reference to a qualified (type- or term-) identifier ´e.x´ refers to the member of the type ´T´ of ´e´ which has the name ´x´ in the same namespace as the identifier.
@@ -193,11 +193,11 @@ TypedFunParam ::= id ‘:’ Type
193
193
194
194
The concrete function type ´(T_1, ..., T_n) \Rightarrow R´ represents the set of function values that take arguments of types ´T_1, ..., Tn´ and yield results of type ´R´.
195
195
The case of exactly one argument type ´T \Rightarrow R´ is a shorthand for ´(T) \Rightarrow R´.
196
-
An argument type of the form ´\Rightarrow T´ represents a [call-by-name parameter](04-basic-declarations-and-definitions.html#by-name-parameters) of type ´T´.
196
+
An argument type of the form ´\Rightarrow T´ represents a [call-by-name parameter](04-basic-definitions.html#by-name-parameters) of type ´T´.
197
197
198
198
Function types associate to the right, e.g. ´S \Rightarrow T \Rightarrow R´ is the same as ´S \Rightarrow (T \Rightarrow R)´.
199
199
200
-
Function types are [covariant](04-basic-declarations-and-definitions.md#variance-annotations) in their result type and [contravariant](04-basic-declarations-and-definitions.md#variance-annotations) in their argument types.
200
+
Function types are [covariant](04-basic-definitions.md#variance-annotations) in their result type and [contravariant](04-basic-definitions.md#variance-annotations) in their argument types.
201
201
202
202
Function types translate into internal class types that define an `apply` method.
203
203
Specifically, the ´n´-ary function type ´(T_1, ..., T_n) \Rightarrow R´ translates to the internal class type `scala.Function´_n´[´T_1´, ..., ´T_n´, ´R´]`.
In the concrete syntax of types, refinements can contain several refined declarations.
264
-
Moreover, the refined declarations can refer to each other as well as to members of the parent type, i.e., they have access to `this`.
263
+
In the concrete syntax of types, refinements can contain several refined definitions.
264
+
They must all be abstract.
265
+
Moreover, the refined definitions can refer to each other as well as to members of the parent type, i.e., they have access to `this`.
265
266
266
-
In the internal types, each refinement defines exactly one refined declaration, and references to `this` must be made explicit in a recursive type.
267
+
In the internal types, each refinement defines exactly one refined definition, and references to `this` must be made explicit in a recursive type.
267
268
268
269
The conversion from the concrete syntax to the abstract syntax works as follows:
269
270
270
271
1. Create a fresh recursive this name ´\alpha´.
271
-
2. Replace every implicit or explicit reference to `this` in the refinement declarations by ´\alpha´.
272
-
3. Create nested [refined types](#refined-types), one for every refined declaration.
272
+
2. Replace every implicit or explicit reference to `this` in the refinement definitions by ´\alpha´.
273
+
3. Create nested [refined types](#refined-types), one for every refined definition.
273
274
4. Unless ´\alpha´ was never actually used, wrap the result in a [recursive type](#recursive-types)`{ ´\alpha´ => ´...´ }`.
274
275
275
276
### Concrete Type Lambdas
@@ -361,7 +362,7 @@ To each type constructor corresponds an _inferred type parameter clause_ which i
361
362
362
363
### Type Definitions
363
364
364
-
A _type definition_ ´D´ represents the right-hand-side of a `type`declaration or the bounds of a type parameter.
365
+
A _type definition_ ´D´ represents the right-hand-side of a `type`member definition or the bounds of a type parameter.
365
366
It is either:
366
367
367
368
- a type alias of the form ´= U´, or
@@ -465,7 +466,7 @@ If the class is monomorphic, the type designator is a value type denoting the se
465
466
Otherwise it is a type constructor with the same type parameters as the class definition.
466
467
All class types are concrete, non-stable types.
467
468
468
-
If a type designator ´p.T´ is not a class type, it refers to a type definition `T` (a type parameter or a `type`declaration) and has an _underlying [type definition](#type-definitions)_.
469
+
If a type designator ´p.T´ is not a class type, it refers to a type definition `T` (a type parameter or a `type`member definition) and has an _underlying [type definition](#type-definitions)_.
469
470
If ´p = \epsilon´ or ´p´ is a package ref, the underlying type definition is the _declared type definition_ of `T`.
470
471
Otherwise, it is determined by [`memberType`](#member-type)`(´p´, ´T´)`.
471
472
A non-class type designator is concrete (resp. stable) if and only if its underlying type definition is an alias ´U´ and ´U´ is itself concrete (resp. stable).
@@ -860,7 +861,7 @@ If a method name is used as a value, its type is [implicitly converted](06-expre
860
861
861
862
###### Example
862
863
863
-
The declarations
864
+
The definitions
864
865
865
866
```scala
866
867
defa:Int
@@ -889,7 +890,7 @@ This type represents named methods that take type arguments `´S_1, ..., S_n´`
889
890
890
891
###### Example
891
892
892
-
The declarations
893
+
The definitions
893
894
894
895
```scala
895
896
defempty[A]:List[A]
@@ -1030,7 +1031,7 @@ We define `memberType(´T´, ´id´, ´p´)` as follows:
1030
1031
- If ´T´ is a possibly parameterized class type of the form ´q.C[T_1, ..., T_n]´ (with ´n \geq 0´):
1031
1032
- Let ´m´ be the [class member](05-classes-and-objects.html#class-members) of ´C´ with name ´id´.
1032
1033
- If ´m´ is not defined, the result is undefined.
1033
-
- If ´m´ is a class declaration, the result is a class result with class ´m´.
1034
+
- If ´m´ is a class definition, the result is a class result with class ´m´.
1034
1035
- If ´m´ is a term definition in class ´D´ with declared type ´U´, the result is a term result with underlying type [`asSeenFrom`](#as-seen-from)`(´U´, ´D´, ´p´)` and stable flag true if and only if ´m´ is stable.
1035
1036
- If ´m´ is a type member definition in class ´D´, the result is a type result with underlying type definition [`asSeenFrom`](#as-seen-from)`(´U´, ´D´, ´p´)` where ´U´ is defined as follows:
1036
1037
- If ´m´ is an opaque type alias member definition with declared definition ´>: L <: H = V´, then
0 commit comments