Skip to content

Commit eeba018

Browse files
committed
Merge pull request scala#4404 from soc/topic/spec
Spec improvements
2 parents 48f4a99 + 62db8d9 commit eeba018

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1618
-465
lines changed

spec/01-lexical-syntax.md

Lines changed: 166 additions & 182 deletions
Large diffs are not rendered by default.

spec/02-identifiers-names-and-scopes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Identifiers, Names and Scopes
2+
title: Identifiers, Names & Scopes
33
layout: default
44
chapter: 2
55
---
@@ -69,7 +69,7 @@ the member of the type $T$ of $e$ which has the name $x$ in the same
6969
namespace as the identifier. It is an error if $T$ is not a [value type](03-types.html#value-types).
7070
The type of $e.x$ is the member type of the referenced entity in $T$.
7171

72-
### Example
72+
###### Example
7373

7474
Assume the following two definitions of objects named `X` in packages `P` and `Q`.
7575

spec/03-types.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ A qualified type designator has the form `p.t` where `p` is
147147
a [path](#paths) and _t_ is a type name. Such a type designator is
148148
equivalent to the type projection `p.type#t`.
149149

150-
### Example
150+
###### Example
151151

152152
Some type designators and their expansions are listed below. We assume
153153
a local type parameter $t$, a value `maintable`
@@ -178,7 +178,8 @@ well-formed if each actual type parameter
178178
_conforms to its bounds_, i.e. $\sigma L_i <: T_i <: \sigma U_i$ where $\sigma$ is the
179179
substitution $[ a_1 := T_1 , \ldots , a_n := T_n ]$.
180180

181-
### Example Parameterized Types
181+
###### Example Parameterized Types
182+
182183
Given the partial type definitions:
183184

184185
```scala
@@ -202,7 +203,7 @@ F[List, Int]
202203
G[S, String]
203204
```
204205

205-
### Example
206+
###### Example
206207

207208
Given the [above type definitions](#example-parameterized-types),
208209
the following types are ill-formed:
@@ -255,10 +256,10 @@ AnnotType ::= SimpleType {Annotation}
255256
```
256257

257258
An annotated type $T$ $a_1, \ldots, a_n$
258-
attaches [annotations](11-user-defined-annotations.html#user-defined-annotations)
259+
attaches [annotations](11-annotations.html#user-defined-annotations)
259260
$a_1 , \ldots , a_n$ to the type $T$.
260261

261-
### Example
262+
###### Example
262263

263264
The following type adds the `@suspendable` annotation to the type `String`:
264265

@@ -304,7 +305,7 @@ A compound type may also consist of just a refinement
304305
$\\{ R \\}$ with no preceding component types. Such a type is
305306
equivalent to `AnyRef` $\\{ R \\}$.
306307

307-
### Example
308+
###### Example
308309

309310
The following example shows how to declare and use a method which
310311
a parameter type that contains a refinement with structural declarations.
@@ -500,7 +501,7 @@ or [tuple types](#tuple-types).
500501
Their expansion is then the expansion in the equivalent parameterized
501502
type.
502503

503-
### Example
504+
###### Example
504505

505506
Assume the class definitions
506507

@@ -524,15 +525,15 @@ An alternative formulation of the first type above using wildcard syntax is:
524525
Ref[_ <: java.lang.Number]
525526
```
526527

527-
### Example
528+
###### Example
528529

529530
The type `List[List[_]]` is equivalent to the existential type
530531

531532
```scala
532533
List[List[t] forSome { type t }] .
533534
```
534535

535-
### Example
536+
###### Example
536537

537538
Assume a covariant type
538539

@@ -658,7 +659,7 @@ same name, we model
658659
659660
An overloaded type consisting of type alternatives $T_1 \commadots T_n (n \geq 2)$ is denoted internally $T_1 \overload \ldots \overload T_n$.
660661
661-
### Example
662+
###### Example
662663
```
663664
def println: Unit
664665
def println(s: String): Unit = $\ldots$
@@ -676,7 +677,7 @@ println: => Unit $\overload$
676677
[A] (A) (A => String) Unit
677678
```
678679
679-
### Example
680+
###### Example
680681
```
681682
def f(x: T): T = $\ldots$
682683
val f = 0

spec/04-basic-declarations-and-definitions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Basic Declarations and Definitions
2+
title: Basic Declarations & Definitions
33
layout: default
44
chapter: 4
55
---
@@ -563,7 +563,7 @@ abstract class Sequence[+A] {
563563
}
564564
```
565565

566-
### Example
566+
###### Example
567567

568568
```scala
569569
abstract class OutputChannel[-A] {

spec/05-classes-and-objects.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Classes and Objects
2+
title: Classes & Objects
33
layout: default
44
chapter: 5
55
---
@@ -368,7 +368,7 @@ it is possible to add new defaults (if the corresponding parameter in the
368368
superclass does not have a default) or to override the defaults of the
369369
superclass (otherwise).
370370

371-
### Example
371+
###### Example
372372

373373
Consider the definitions:
374374

@@ -699,7 +699,7 @@ Here,
699699
parameter section is called _polymorphic_, otherwise it is called
700700
_monomorphic_.
701701
- $as$ is a possibly empty sequence of
702-
[annotations](11-user-defined-annotations.html#user-defined-annotations).
702+
[annotations](11-annotations.html#user-defined-annotations).
703703
If any annotations are given, they apply to the primary constructor of the
704704
class.
705705
- $m$ is an [access modifier](#modifiers) such as
@@ -744,7 +744,7 @@ which when applied to parameters conforming to types $\mathit{ps}$
744744
initializes instances of type `$c$[$\mathit{tps}\,$]` by evaluating the template
745745
$t$.
746746
747-
### Example
747+
###### Example
748748
The following example illustrates `val` and `var` parameters of a class `C`:
749749
750750
```scala
@@ -990,7 +990,7 @@ it is not statically known at the time the trait is defined.
990990
If $D$ is not a trait, then its actual supertype is simply its
991991
least proper supertype (which is statically known).
992992

993-
### Example
993+
###### Example
994994
The following trait defines the property
995995
of being comparable to objects of some type. It contains an abstract
996996
method `<` and default implementations of the other

spec/06-expressions.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ to the type or method of $x$ in the parent trait of $C$ whose simple
205205
name is $T$. That member must be uniquely defined. If it is a method,
206206
it must be concrete.
207207

208-
### Example
208+
###### Example
209209
Consider the following class definitions
210210

211211
```scala
@@ -778,7 +778,7 @@ Expr1 ::= PostfixExpr `:' Annotation {Annotation}
778778
```
779779

780780
An annotated expression `$e$: @$a_1$ $\ldots$ @$a_n$`
781-
attaches [annotations](11-user-defined-annotations.html#user-defined-annotations) $a_1 , \ldots , a_n$ to the
781+
attaches [annotations](11-annotations.html#user-defined-annotations) $a_1 , \ldots , a_n$ to the
782782
expression $e$.
783783

784784
## Assignments
@@ -815,7 +815,7 @@ Here are some assignment expressions and their equivalent expansions.
815815
|`x.f(i) = e` | `x.f.update(i, e)` |
816816
|`x.f(i, j) = e` | `x.f.update(i, j, e)`|
817817

818-
### Example Imperative Matrix Multiplication
818+
###### Example Imperative Matrix Multiplication
819819

820820
Here is the usual imperative code for matrix multiplication.
821821

@@ -1221,9 +1221,9 @@ In that case, a fresh name for the parameter is chosen arbitrarily.
12211221

12221222
A named parameter of an anonymous function may be optionally preceded
12231223
by an `implicit` modifier. In that case the parameter is
1224-
labeled [`implicit`](07-implicit-parameters-and-views.html#implicit-parameters-and-views); however the
1224+
labeled [`implicit`](07-implicits.html#implicit-parameters-and-views); however the
12251225
parameter section itself does not count as an implicit parameter
1226-
section in the sense defined [here](07-implicit-parameters-and-views.html#implicit-parameters). Hence, arguments to
1226+
section in the sense defined [here](07-implicits.html#implicit-parameters). Hence, arguments to
12271227
anonymous functions always have to be given explicitly.
12281228

12291229
###### Example
@@ -1341,7 +1341,7 @@ available implicit conversions are given in the next two sub-sections.
13411341

13421342
We say, a type $T$ is _compatible_ to a type $U$ if $T$ weakly conforms
13431343
to $U$ after applying [eta-expansion](#eta-expansion) and
1344-
[view applications](07-implicit-parameters-and-views.html#views).
1344+
[view applications](07-implicits.html#views).
13451345

13461346
### Value Conversions
13471347

@@ -1389,7 +1389,7 @@ term `{ $e$; () }`.
13891389
###### View Application
13901390
If none of the previous conversions applies, and $e$'s type
13911391
does not conform to the expected type $\mathit{pt}$, it is attempted to convert
1392-
$e$ to the expected type with a [view](07-implicit-parameters-and-views.html#views).
1392+
$e$ to the expected type with a [view](07-implicits.html#views).
13931393

13941394
###### Dynamic Member Selection
13951395
If none of the previous conversions applies, and $e$ is a prefix
@@ -1408,7 +1408,7 @@ type $T$ by evaluating the expression to which $m$ is bound.
14081408

14091409
###### Implicit Application
14101410
If the method takes only implicit parameters, implicit
1411-
arguments are passed following the rules [here](07-implicit-parameters-and-views.html#implicit-parameters).
1411+
arguments are passed following the rules [here](07-implicits.html#implicit-parameters).
14121412

14131413
###### Eta Expansion
14141414
Otherwise, if the method is not a constructor,

spec/07-implicit-parameters-and-views.md renamed to spec/07-implicits.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Implicit Parameters and Views
2+
title: Implicits
33
layout: default
44
chapter: 7
55
---
66

7-
# Implicit Parameters and Views
7+
# Implicits
88

99
## The Implicit Modifier
1010

@@ -19,7 +19,8 @@ and can be used as implicit conversions called [views](#views).
1919
The `implicit` modifier is illegal for all
2020
type members, as well as for [top-level objects](09-top-level-definitions.html#packagings).
2121

22-
### Example Monoid
22+
###### Example Monoid
23+
2324
The following code defines an abstract class of monoids and
2425
two concrete implementations, `StringMonoid` and
2526
`IntMonoid`. The two implementations are marked implicit.
@@ -180,7 +181,7 @@ To prevent such infinite expansions, the compiler keeps track of
180181
a stack of “open implicit types” for which implicit arguments are currently being
181182
searched. Whenever an implicit argument for type $T$ is searched, the
182183
“core type” of $T$ is added to the stack. Here, the _core type_
183-
of $T$ is $T$ with aliases expanded, top-level type [annotations](11-user-defined-annotations.html#user-defined-annotations) and
184+
of $T$ is $T$ with aliases expanded, top-level type [annotations](11-annotations.html#user-defined-annotations) and
184185
[refinements](03-types.html#compound-types) removed, and occurrences
185186
of top-level existentially bound variables replaced by their upper
186187
bounds. The core type is removed from the stack once the search for
@@ -284,7 +285,8 @@ As for implicit parameters, overloading resolution is applied
284285
if there are several possible candidates (of either the call-by-value
285286
or the call-by-name category).
286287

287-
### Example Ordered
288+
###### Example Ordered
289+
288290
Class `scala.Ordered[A]` contains a method
289291

290292
```scala

spec/08-pattern-matching.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ bound type variables in a typed pattern or constructor
371371
pattern. Inference takes into account the expected type of the
372372
pattern.
373373

374-
### Type parameter inference for typed patterns.
374+
### Type parameter inference for typed patterns
375375

376376
Assume a typed pattern $p: T'$. Let $T$ result from $T'$ where all wildcards in
377377
$T'$ are renamed to fresh variable names. Let $a_1 , \ldots , a_n$ be
@@ -437,7 +437,7 @@ complexity of inferred bounds. Minimality and maximality of types have
437437
to be understood relative to the set of types of acceptable
438438
complexity.
439439

440-
#### Type parameter inference for constructor patterns.
440+
### Type parameter inference for constructor patterns
441441
Assume a constructor pattern $C(p_1 , \ldots , p_n)$ where class $C$
442442
has type type parameters $a_1 , \ldots , a_n$. These type parameters
443443
are inferred in the same way as for the typed pattern
@@ -593,7 +593,7 @@ the compilation of pattern matching can emit warnings which diagnose
593593
that a given set of patterns is not exhaustive, i.e. that there is a
594594
possibility of a `MatchError` being raised at run-time.
595595

596-
### Example
596+
###### Example
597597

598598
Consider the following definitions of arithmetic terms:
599599

spec/10-xml-expressions-and-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: XML Expressions and Patterns
2+
title: XML
33
layout: default
44
chapter: 10
55
---

spec/11-user-defined-annotations.md renamed to spec/11-annotations.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
---
2-
title: User-Defined Annotations
2+
title: Annotations
33
layout: default
44
chapter: 11
55
---
66

7-
# User-Defined Annotations
7+
# Annotations
88

99
```ebnf
1010
Annotation ::= ‘@’ SimpleType {ArgumentExprs}
1111
ConstrAnnotation ::= ‘@’ SimpleType ArgumentExprs
1212
```
1313

14-
User-defined annotations associate meta-information with definitions.
14+
## Definition
15+
16+
Annotations associate meta-information with definitions.
1517
A simple annotation has the form `@$c$` or `@$c(a_1 , \ldots , a_n)$`.
1618
Here, $c$ is a constructor of a class $C$, which must conform
1719
to the class `scala.Annotation`.
@@ -33,6 +35,10 @@ String @local // Type annotation
3335
(e: @unchecked) match { ... } // Expression annotation
3436
```
3537

38+
## Predefined Annotations
39+
40+
### Java Platform Annotations
41+
3642
The meaning of annotation clauses is implementation-dependent. On the
3743
Java platform, the following annotations have a standard meaning.
3844

@@ -61,7 +67,7 @@ Java platform, the following annotations have a standard meaning.
6167
clause for the method or constructor must mention the class of that exception
6268
or one of the superclasses of the class of that exception.
6369
64-
## Java Beans Annotations
70+
### Java Beans Annotations
6571
6672
* `@scala.beans.BeanProperty` When prefixed to a definition of some variable `X`, this
6773
annotation causes getter and setter methods `getX`, `setX`
@@ -76,18 +82,21 @@ Java platform, the following annotations have a standard meaning.
7682
* `@scala.beans.BooleanBeanProperty` This annotation is equivalent to `scala.reflect.BeanProperty`, but
7783
the generated getter method is named `isX` instead of `getX`.
7884
79-
## Deprecation Annotations
85+
### Deprecation Annotations
8086
81-
* `@deprecated(<stringlit>)` Marks a definition as deprecated. Accesses to the
87+
* `@deprecated(message: <stringlit>, since: <stringlit>)`<br/>
88+
Marks a definition as deprecated. Accesses to the
8289
defined entity will then cause a deprecated warning mentioning the
83-
message `<stringlit>` to be issued from the compiler. Deprecated
84-
warnings are suppressed in code that belongs itself to a definition
90+
_message_ `<stringlit>` to be issued from the compiler.
91+
The argument _since_ documents since when the definition should be considered deprecated.<br/>
92+
Deprecated warnings are suppressed in code that belongs itself to a definition
8593
that is labeled deprecated.
8694
87-
* `@deprecatedName(name: <symbollit>)` Marks a formal parameter name as deprecated. Invocations of this entity
95+
* `@deprecatedName(name: <symbollit>)`<br/>
96+
Marks a formal parameter name as deprecated. Invocations of this entity
8897
using named parameter syntax refering to the deprecated parameter name cause a deprecation warning.
8998
90-
## Scala Compiler Annotations
99+
### Scala Compiler Annotations
91100
92101
* `@unchecked` When applied to the selector of a `match` expression,
93102
this attribute suppresses any warnings about non-exhaustive pattern
@@ -141,6 +150,8 @@ Java platform, the following annotations have a standard meaning.
141150
a definition, the compiler will instead use the specialized version.
142151
See the [specialization sid](http://docs.scala-lang.org/sips/completed/scala-specialization.html) for more details of the implementation.
143152
153+
## User-defined Annotations
154+
144155
Other annotations may be interpreted by platform- or
145156
application-dependent tools. Class `scala.Annotation` has two
146157
sub-traits which are used to indicate how these annotations are

0 commit comments

Comments
 (0)