Skip to content

Commit 2a1e3de

Browse files
authored
Remainder of the Spec updates about removals (#16841)
This is the rest of the work I (Sporarum) did on the Spec about feature removals. It is not in individual PRs, but still follows the other principles outlined in #16839 and in `docs/_spec/README.md`.
2 parents 2c4502b + 3a4e1cc commit 2a1e3de

22 files changed

+224
-391
lines changed

docs/_spec/01-lexical-syntax.md

+1-12
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ A single new line token is accepted
259259
260260
## Literals
261261
262-
There are literals for integer numbers, floating point numbers, characters, booleans, symbols, strings.
262+
There are literals for integer numbers, floating point numbers, characters, booleans, strings.
263263
The syntax of these literals is in each case as in Java.
264264
265265
<!-- TODO
@@ -274,7 +274,6 @@ Literal ::= [‘-’] integerLiteral
274274
| characterLiteral
275275
| stringLiteral
276276
| interpolatedString
277-
| symbolLiteral
278277
|null
279278
```
280279
@@ -490,16 +489,6 @@ In addition, Unicode escape sequences of the form `\uxxxx`, where each `x` is a
490489
491490
It is a compile time error if a backslash character in a character or string literal does not start a valid escape sequence.
492491
493-
### Symbol literals
494-
495-
```ebnf
496-
symbolLiteral ::= ‘'’ plainid
497-
```
498-
499-
A symbol literal `'x` is deprecated shorthand for the expression `scala.Symbol("x")`.
500-
501-
The `apply` method of `Symbol`'s companion object caches weak references to `Symbol`s, thus ensuring that identical symbol literals are equivalent with respect to reference equality.
502-
503492
## Whitespace and Comments
504493
505494
Tokens may be separated by whitespace characters and/or comments.

docs/_spec/03-types.md

+89-173
Large diffs are not rendered by default.

docs/_spec/04-basic-declarations-and-definitions.md

+2-79
Original file line numberDiff line numberDiff line change
@@ -40,53 +40,15 @@ by commas. These are expanded according to the following scheme:
4040
\VAL;x, y: T = e && \VAL; x: T = e \\
4141
&& \VAL; y: T = x \\[0.5em]
4242
43-
\LET;x, y: T = e && \LET; x: T = e \\
44-
&& \VAL; y: T = x \\[0.5em]
45-
46-
\DEF;x, y (ps): T = e &\tab\mbox{expands to}\tab& \DEF; x(ps): T = e \\
47-
&& \DEF; y(ps): T = x(ps)\\[0.5em]
48-
4943
\VAR;x, y: T := e && \VAR;x: T := e\\
5044
&& \VAR;y: T := x\\[0.5em]
51-
52-
\TYPE;t,u = T && \TYPE; t = T\\
53-
&& \TYPE; u = t\\[0.5em]
5445
\eda
5546
56-
All definitions have a ``repeated form`` where the initial
57-
definition keyword is followed by several constituent definitions
58-
which are separated by commas. A repeated definition is
59-
always interpreted as a sequence formed from the
60-
constituent definitions. E.g. the function definition
61-
`def f(x) = x, g(y) = y` expands to
62-
`def f(x) = x; def g(y) = y` and
63-
the type definition
64-
`type T, U <: B` expands to
65-
`type T; type U <: B`.
66-
}
67-
\comment{
68-
If an element in such a sequence introduces only the defined name,
69-
possibly with some type or value parameters, but leaves out any
70-
additional parts in the definition, then those parts are implicitly
71-
copied from the next subsequent sequence element which consists of
72-
more than just a defined name and parameters. Examples:
73-
74-
- []
7547
The variable declaration `var x, y: Int`
7648
expands to `var x: Int; var y: Int`.
77-
- []
49+
7850
The value definition `val x, y: Int = 1`
7951
expands to `val x: Int = 1; val y: Int = 1`.
80-
- []
81-
The class definition `case class X(), Y(n: Int) extends Z` expands to
82-
`case class X extends Z; case class Y(n: Int) extends Z`.
83-
- The object definition `case object Red, Green, Blue extends Color`~
84-
expands to
85-
```scala
86-
case object Red extends Color
87-
case object Green extends Color
88-
case object Blue extends Color
89-
```
9052
-->
9153

9254
## Value Declarations and Definitions
@@ -647,49 +609,10 @@ By contrast, the following application is well formed and yields again the resul
647609
sum(xs: _*)
648610
```
649611

650-
### Procedures
651-
652-
```ebnf
653-
FunDcl ::= FunSig
654-
FunDef ::= FunSig [nl] ‘{’ Block ‘}’
655-
```
656-
657-
Special syntax exists for procedures, i.e. methods that return the `Unit` value `()`.
658-
A _procedure declaration_ is a method declaration where the result type is omitted.
659-
The result type is then implicitly completed to the `Unit` type. E.g., `def ´f´(´\mathit{ps}´)` is equivalent to `def ´f´(´\mathit{ps}´): Unit`.
660-
661-
A _procedure definition_ is a method definition where the result type and the equals sign are omitted; its defining expression must be a block.
662-
E.g., `def ´f´(´\mathit{ps}´) {´\mathit{stats}´}` is equivalent to `def ´f´(´\mathit{ps}´): Unit = {´\mathit{stats}´}`.
663-
664-
###### Example
665-
Here is a declaration and a definition of a procedure named `write`:
666-
667-
```scala
668-
trait Writer {
669-
def write(str: String)
670-
}
671-
object Terminal extends Writer {
672-
def write(str: String) { System.out.println(str) }
673-
}
674-
```
675-
676-
The code above is implicitly completed to the following code:
677-
678-
```scala
679-
trait Writer {
680-
def write(str: String): Unit
681-
}
682-
object Terminal extends Writer {
683-
def write(str: String): Unit = { System.out.println(str) }
684-
}
685-
```
686-
687612
### Method Return Type Inference
688613

689614
A class member definition ´m´ that overrides some other method ´m'´ in a base class of ´C´ may leave out the return type, even if it is recursive.
690-
In this case, the return type ´R'´ of the overridden method ´m'´, seen as a member of ´C´, is taken as the return type of ´m´ for each recursive invocation of ´m´.
691-
That way, a type ´R´ for the right-hand side of ´m´ can be determined, which is then taken as the return type of ´m´.
692-
Note that ´R´ may be different from ´R'´, as long as ´R´ conforms to ´R'´.
615+
In this case, whether or not `m` is recursive, its return type will be the return type of ´m'´.
693616

694617
###### Example
695618
Assume the following definitions:

docs/_spec/05-classes-and-objects.md

+1-62
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,6 @@ If this is not a template of a trait, then its _evaluation_ consists of the foll
9696
Mixin-evaluation happens in reverse order of occurrence in the linearization.
9797
- Finally, the statement sequence ´\mathit{stats}\,´ is evaluated.
9898

99-
###### Delayed Initialization
100-
This statement sequence constitutes the initialization code for an object or class after the superclass constructor invocation and the mixin-evaluation of the template's base classes as described above.
101-
Normally, this code is passed to a special hook, inaccessible to user code, which simply executes it.
102-
103-
However, in objects and classes (but not traits) which extend `scala.DelayedInit`, the initialization code is passed to a `delayedInit` method which can be overridden to implement arbitrary semantics.
104-
105-
```scala
106-
def delayedInit(body: => Unit): Unit
107-
```
108-
10999
### Constructor Invocations
110100

111101
```ebnf
@@ -305,57 +295,6 @@ It is a static error if the inheritance closure of a class type consists of an i
305295

306296
[^kennedy]: Kennedy, Pierce. [On Decidability of Nominal Subtyping with Variance.]( https://research.microsoft.com/pubs/64041/fool2007.pdf) in FOOL 2007
307297

308-
### Early Definitions
309-
310-
```ebnf
311-
EarlyDefs ::= ‘{’ [EarlyDef {semi EarlyDef}] ‘}’ ‘with’
312-
EarlyDef ::= {Annotation} {Modifier} PatVarDef
313-
```
314-
315-
A template may start with an _early field definition_ clause, which serves to define certain field values before the supertype constructor is called.
316-
In a template
317-
318-
```scala
319-
{ val ´p_1´: ´T_1´ = ´e_1´
320-
...
321-
val ´p_n´: ´T_n´ = ´e_n´
322-
} with ´sc´ with ´mt_1´ with ´mt_n´ { ´\mathit{stats}´ }
323-
```
324-
325-
The initial pattern definitions of ´p_1 , \ldots , p_n´ are called _early definitions_.
326-
They define fields which form part of the template.
327-
Every early definition must define at least one variable.
328-
329-
An early definition is type-checked and evaluated in the scope which is in effect just before the template being defined, augmented by any type parameters of the enclosing class and by any early definitions preceding the one being defined.
330-
In particular, any reference to `this` in an early definition refers to the identity of `this` just outside the template.
331-
Consequently, it is impossible for an early definition to refer to the object being constructed by the template, or to refer to one of its fields and methods, except for any other preceding early definition in the same section.
332-
Furthermore, references to preceding early definitions always refer to the value that's defined there and do not take into account overriding definitions.
333-
In other words, a block of early definitions is evaluated exactly as if it were a local block containing a number of value definitions.
334-
335-
Early definitions are evaluated before the superclass constructor of the template is called, in the order they are defined.
336-
337-
###### Example
338-
Early definitions are particularly useful for traits, which do not have normal constructor parameters.
339-
Example:
340-
341-
```scala
342-
trait Greeting {
343-
val name: String
344-
val msg = "How are you, "+name
345-
}
346-
class C extends {
347-
val name = "Bob"
348-
} with Greeting {
349-
println(msg)
350-
}
351-
```
352-
353-
In the code above, the field `name` is initialized before the constructor of `Greeting` is called.
354-
Therefore, field `msg` in class `Greeting` is properly initialized to `"How are you, Bob"`.
355-
356-
If `name` had been initialized instead in `C`'s normal class body, it would be initialized after the constructor of `Greeting`.
357-
In that case, `msg` would be initialized to `"How are you, <null>"`.
358-
359298
## Modifiers
360299

361300
```ebnf
@@ -602,7 +541,7 @@ A constructor expression is either a self constructor invocation `this(´\mathit
602541
The self constructor invocation must construct a generic instance of the class.
603542
I.e. if the class in question has name ´C´ and type parameters `[´\mathit{tps}\,´]`, then a self constructor invocation must generate an instance of `´C´[´\mathit{tps}\,´]`; it is not permitted to instantiate formal type parameters.
604543

605-
The signature and the self constructor invocation of a constructor definition are type-checked and evaluated in the scope which is in effect at the point of the enclosing class definition, augmented by any type parameters of the enclosing class and by any [early definitions](#early-definitions) of the enclosing template.
544+
The signature and the self constructor invocation of a constructor definition are type-checked and evaluated in the scope which is in effect at the point of the enclosing class definition, augmented by any type parameters of the enclosing class.
606545
The rest of the constructor expression is type-checked and evaluated as a method body in the current class.
607546

608547
If there are auxiliary constructors of a class ´C´, they form together with ´C´'s primary [constructor](#class-definitions) an overloaded constructor definition.

0 commit comments

Comments
 (0)