summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/01-lexical-syntax.md46
-rw-r--r--spec/02-identifiers-names-and-scopes.md91
-rw-r--r--spec/03-types.md133
-rw-r--r--spec/04-basic-declarations-and-definitions.md27
-rw-r--r--spec/05-classes-and-objects.md103
-rw-r--r--spec/06-expressions.md432
-rw-r--r--spec/07-implicits.md8
-rw-r--r--spec/08-pattern-matching.md65
-rw-r--r--spec/09-top-level-definitions.md6
-rw-r--r--spec/10-xml-expressions-and-patterns.md4
-rw-r--r--spec/11-annotations.md10
-rw-r--r--spec/12-the-scala-standard-library.md8
-rw-r--r--spec/13-syntax-summary.md37
-rw-r--r--spec/15-changelog.md4
-rw-r--r--spec/README.md12
-rw-r--r--spec/_config.yml4
-rw-r--r--spec/_layouts/default.yml2
-rw-r--r--spec/_layouts/toc.yml4
-rw-r--r--spec/id_dsa_travis.enc83
19 files changed, 594 insertions, 485 deletions
diff --git a/spec/01-lexical-syntax.md b/spec/01-lexical-syntax.md
index 53c8caf745..78f1a1a408 100644
--- a/spec/01-lexical-syntax.md
+++ b/spec/01-lexical-syntax.md
@@ -41,7 +41,7 @@ classes (Unicode general category given in parentheses):
1. Parentheses `‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’ `.
1. Delimiter characters ``‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’ ``.
1. Operator characters. These consist of all printable ASCII characters
- `\u0020` - `\u007F` which are in none of the sets above, mathematical
+ (`\u0020` - `\u007E`) that are in none of the sets above, mathematical
symbols (`Sm`) and other symbols (`So`).
## Identifiers
@@ -49,11 +49,13 @@ classes (Unicode general category given in parentheses):
```ebnf
op ::= opchar {opchar}
varid ::= lower idrest
+boundvarid ::= varid
+ | ‘`’ varid ‘`’
plainid ::= upper idrest
| varid
| op
id ::= plainid
- | ‘`’ stringLiteral ‘`’
+ | ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
idrest ::= {letter | digit} [‘_’ op]
```
@@ -398,40 +400,46 @@ members of type `Boolean`.
### Character Literals
```ebnf
-characterLiteral ::= ‘'’ (printableChar | charEscapeSeq) ‘'’
+characterLiteral ::= ‘'’ (charNoQuoteOrNewline | UnicodeEscape | charEscapeSeq) ‘'’
```
A character literal is a single character enclosed in quotes.
-The character is either a printable unicode character or is described
-by an [escape sequence](#escape-sequences).
+The character can be any Unicode character except the single quote
+delimiter or `\u000A` (LF) or `\u000D` (CR);
+or any Unicode character represented by either a
+[Unicode escape](01-lexical-syntax.html) or by an [escape sequence](#escape-sequences).
> ```scala
> 'a' '\u0041' '\n' '\t'
> ```
-Note that `'\u000A'` is _not_ a valid character literal because
-Unicode conversion is done before literal parsing and the Unicode
-character `\u000A` (line feed) is not a printable
-character. One can use instead the escape sequence `'\n'` or
-the octal escape `'\12'` ([see here](#escape-sequences)).
+Note that although Unicode conversion is done early during parsing,
+so that Unicode characters are generally equivalent to their escaped
+expansion in the source text, literal parsing accepts arbitrary
+Unicode escapes, including the character literal `'\u000A'`,
+which can also be written using the escape sequence `'\n'`.
### String Literals
```ebnf
stringLiteral ::= ‘"’ {stringElement} ‘"’
-stringElement ::= printableCharNoDoubleQuote | charEscapeSeq
+stringElement ::= charNoDoubleQuoteOrNewline | UnicodeEscape | charEscapeSeq
```
-A string literal is a sequence of characters in double quotes. The
-characters are either printable unicode character or are described by
-[escape sequences](#escape-sequences). If the string literal
-contains a double quote character, it must be escaped,
-i.e. `"\""`. The value of a string literal is an instance of
-class `String`.
+A string literal is a sequence of characters in double quotes.
+The characters can be any Unicode character except the double quote
+delimiter or `\u000A` (LF) or `\u000D` (CR);
+or any Unicode character represented by either a
+[Unicode escape](01-lexical-syntax.html) or by an [escape sequence](#escape-sequences).
+
+If the string literal contains a double quote character, it must be escaped using
+`"\""`.
+
+The value of a string literal is an instance of class `String`.
> ```scala
-> "Hello,\nWorld!"
-> "This string contains a \" character."
+> "Hello, world!\n"
+> "\"Hello,\" replied the world."
> ```
#### Multi-Line String Literals
diff --git a/spec/02-identifiers-names-and-scopes.md b/spec/02-identifiers-names-and-scopes.md
index 0a9c5dfe77..6653be2ce5 100644
--- a/spec/02-identifiers-names-and-scopes.md
+++ b/spec/02-identifiers-names-and-scopes.md
@@ -17,12 +17,12 @@ which are collectively called _bindings_.
Bindings of different kinds have a precedence defined on them:
1. Definitions and declarations that are local, inherited, or made
- available by a package clause in the same compilation unit where the
- definition occurs have highest precedence.
+ available by a package clause and also defined in the same compilation unit
+ as the reference, have highest precedence.
1. Explicit imports have next highest precedence.
1. Wildcard imports have next highest precedence.
-1. Definitions made available by a package clause not in the
- compilation unit where the definition occurs have lowest precedence.
+1. Definitions made available by a package clause, but not also defined in the
+ same compilation unit as the reference, have lowest precedence.
There are two different name spaces, one for [types](03-types.html#types)
and one for [terms](06-expressions.html#expressions). The same name may designate a
@@ -34,22 +34,18 @@ in some inner scope _shadows_ bindings of lower precedence in the
same scope as well as bindings of the same or lower precedence in outer
scopes.
-<!-- TODO: either the example, the spec, or the compiler is wrong
-
-Note that shadowing is only a partial order. In a situation like
+Note that shadowing is only a partial order. In the following example,
+neither binding of `x` shadows the other. Consequently, the
+reference to `x` in the last line of the block is ambiguous.
```scala
val x = 1
-{
- import p.x
+locally {
+ import p.X.x
x
}
```
-neither binding of `x` shadows the other. Consequently, the
-reference to `x` in the last line of the block above would be ambiguous.
--->
-
A reference to an unqualified (type- or term-) identifier $x$ is bound
by the unique binding, which
@@ -69,17 +65,36 @@ the member of the type $T$ of $e$ which has the name $x$ in the same
namespace as the identifier. It is an error if $T$ is not a [value type](03-types.html#value-types).
The type of $e.x$ is the member type of the referenced entity in $T$.
+Binding precedence implies that the way source is bundled in files affects name resolution.
+In particular, imported names have higher precedence than names, defined in other files,
+that might otherwise be visible because they are defined in
+either the current package or an enclosing package.
+
+Note that a package definition is taken as lowest precedence, since packages
+are open and can be defined across arbitrary compilation units.
+
+```scala
+package util {
+ import scala.util
+ class Random
+ object Test extends App {
+ println(new util.Random) // scala.util.Random
+ }
+}
+```
+
###### Example
-Assume the following two definitions of objects named `X` in packages `P` and `Q`.
+Assume the following two definitions of objects named `X` in packages `p` and `q`
+in separate compilation units.
```scala
-package P {
+package p {
object X { val x = 1; val y = 2 }
}
-package Q {
- object X { val x = true; val y = "" }
+package q {
+ object X { val x = true; val y = false }
}
```
@@ -87,25 +102,27 @@ The following program illustrates different kinds of bindings and
precedences between them.
```scala
-package P { // `X' bound by package clause
-import Console._ // `println' bound by wildcard import
-object A {
- println("L4: "+X) // `X' refers to `P.X' here
- object B {
- import Q._ // `X' bound by wildcard import
- println("L7: "+X) // `X' refers to `Q.X' here
- import X._ // `x' and `y' bound by wildcard import
- println("L8: "+x) // `x' refers to `Q.X.x' here
- object C {
- val x = 3 // `x' bound by local definition
- println("L12: "+x) // `x' refers to constant `3' here
- { import Q.X._ // `x' and `y' bound by wildcard import
-// println("L14: "+x) // reference to `x' is ambiguous here
- import X.y // `y' bound by explicit import
- println("L16: "+y) // `y' refers to `Q.X.y' here
- { val x = "abc" // `x' bound by local definition
- import P.X._ // `x' and `y' bound by wildcard import
-// println("L19: "+y) // reference to `y' is ambiguous here
- println("L20: "+x) // `x' refers to string "abc" here
+package p { // `X' bound by package clause
+import Console._ // `println' bound by wildcard import
+object Y {
+ println(s"L4: $X") // `X' refers to `p.X' here
+ locally {
+ import q._ // `X' bound by wildcard import
+ println(s"L7: $X") // `X' refers to `q.X' here
+ import X._ // `x' and `y' bound by wildcard import
+ println(s"L9: $x") // `x' refers to `q.X.x' here
+ locally {
+ val x = 3 // `x' bound by local definition
+ println(s"L12: $x") // `x' refers to constant `3' here
+ locally {
+ import q.X._ // `x' and `y' bound by wildcard import
+// println(s"L15: $x") // reference to `x' is ambiguous here
+ import X.y // `y' bound by explicit import
+ println(s"L17: $y") // `y' refers to `q.X.y' here
+ locally {
+ val x = "abc" // `x' bound by local definition
+ import p.X._ // `x' and `y' bound by wildcard import
+// println(s"L21: $y") // reference to `y' is ambiguous here
+ println(s"L22: $x") // `x' refers to string "abc" here
}}}}}}
```
diff --git a/spec/03-types.md b/spec/03-types.md
index 94b7916634..a3167646ca 100644
--- a/spec/03-types.md
+++ b/spec/03-types.md
@@ -105,7 +105,7 @@ forms.
SimpleType ::= Path ‘.’ type
```
-A singleton type is of the form $p.$`type`, where $p$ is a
+A _singleton type_ is of the form $p.$`type`, where $p$ is a
path pointing to a value expected to [conform](06-expressions.html#expression-typing)
to `scala.AnyRef`. The type denotes the set of values
consisting of `null` and the value denoted by $p$.
@@ -119,7 +119,7 @@ declared to be a subtype of trait `scala.Singleton`.
SimpleType ::= SimpleType ‘#’ id
```
-A type projection $T$#$x$ references the type member named
+A _type projection_ $T$#$x$ references the type member named
$x$ of type $T$.
<!--
@@ -134,7 +134,7 @@ If $x$ references an abstract type member, then $T$ must be a
SimpleType ::= StableId
```
-A type designator refers to a named value type. It can be simple or
+A _type designator_ refers to a named value type. It can be simple or
qualified. All such type designators are shorthands for type projections.
Specifically, the unqualified type name $t$ where $t$ is bound in some
@@ -167,7 +167,7 @@ SimpleType ::= SimpleType TypeArgs
TypeArgs ::= ‘[’ Types ‘]’
```
-A parameterized type $T[ T_1 , \ldots , T_n ]$ consists of a type
+A _parameterized type_ $T[ T_1 , \ldots , T_n ]$ consists of a type
designator $T$ and type parameters $T_1 , \ldots , T_n$ where
$n \geq 1$. $T$ must refer to a type constructor which takes $n$ type
parameters $a_1 , \ldots , a_n$.
@@ -227,7 +227,7 @@ G[S, Int] // illegal: S constrains its parameter to
SimpleType ::= ‘(’ Types ‘)’
```
-A tuple type $(T_1 , \ldots , T_n)$ is an alias for the
+A _tuple type_ $(T_1 , \ldots , T_n)$ is an alias for the
class `scala.Tuple$n$[$T_1$, … , $T_n$]`, where $n \geq 2$.
Tuple classes are case classes whose fields can be accessed using
@@ -255,7 +255,7 @@ trait Product_n[+$T_1$, … , +$T_n$] {
AnnotType ::= SimpleType {Annotation}
```
-An annotated type $T$ $a_1, \ldots, a_n$
+An _annotated type_ $T$ $a_1, \ldots, a_n$
attaches [annotations](11-annotations.html#user-defined-annotations)
$a_1 , \ldots , a_n$ to the type $T$.
@@ -278,7 +278,7 @@ RefineStat ::= Dcl
|
```
-A compound type $T_1$ `with` … `with` $T_n \\{ R \\}$
+A _compound type_ $T_1$ `with` … `with` $T_n \\{ R \\}$
represents objects with members as given in the component types
$T_1 , \ldots , T_n$ and the refinement $\\{ R \\}$. A refinement
$\\{ R \\}$ contains declarations and type definitions.
@@ -343,7 +343,7 @@ a value `callsign` and a `fly` method.
InfixType ::= CompoundType {id [nl] CompoundType}
```
-An infix type $T_1$ `op` $T_2$ consists of an infix
+An _infix type_ $T_1$ `op` $T_2$ consists of an infix
operator `op` which gets applied to two type operands $T_1$ and
$T_2$. The type is equivalent to the type application
`op`$[T_1, T_2]$. The infix operator `op` may be an
@@ -410,7 +410,7 @@ ExistentialDcl ::= ‘type’ TypeDcl
| ‘val’ ValDcl
```
-An existential type has the form `$T$ forSome { $Q$ }`
+An _existential type_ has the form `$T$ forSome { $Q$ }`
where $Q$ is a sequence of
[type declarations](04-basic-declarations-and-definitions.html#type-declarations-and-type-aliases).
@@ -507,7 +507,7 @@ Assume the class definitions
```scala
class Ref[T]
-abstract class Outer { type T } .
+abstract class Outer { type T }
```
Here are some examples of existential types:
@@ -530,7 +530,7 @@ Ref[_ <: java.lang.Number]
The type `List[List[_]]` is equivalent to the existential type
```scala
-List[List[t] forSome { type t }] .
+List[List[t] forSome { type t }]
```
###### Example
@@ -564,7 +564,7 @@ report as the internal types of defined identifiers.
### Method Types
-A method type is denoted internally as $(\mathit{Ps})U$, where $(\mathit{Ps})$
+A _method type_ is denoted internally as $(\mathit{Ps})U$, where $(\mathit{Ps})$
is a sequence of parameter names and types $(p_1:T_1 , \ldots , p_n:T_n)$
for some $n \geq 0$ and $U$ is a (value or method) type. This type
represents named methods that take arguments named $p_1 , \ldots , p_n$
@@ -587,7 +587,7 @@ corresponding function type.
The declarations
-```
+```scala
def a: Int
def b (x: Int): Boolean
def c (x: Int) (y: String, z: String): String
@@ -631,7 +631,7 @@ union : [A >: Nothing <: Comparable[A]] (x: Set[A], xs: Set[A]) Set[A]
### Type Constructors
-A type constructor is represented internally much like a polymorphic method type.
+A _type constructor_ is represented internally much like a polymorphic method type.
`[$\pm$ $a_1$ >: $L_1$ <: $U_1 , \ldots , \pm a_n$ >: $L_n$ <: $U_n$] $T$`
represents a type that is expected by a
[type constructor parameter](04-basic-declarations-and-definitions.html#type-parameters) or an
@@ -642,7 +642,7 @@ the corresponding type parameter clause.
Consider this fragment of the `Iterable[+X]` class:
-```
+```scala
trait Iterable[+X] {
def flatMap[newType[+X] <: Iterable[X], S](f: X => newType[S]): newType[S]
}
@@ -660,7 +660,7 @@ same name, we model
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$.
###### Example
-```
+```scala
def println: Unit
def println(s: String): Unit = $\ldots$
def println(x: Float): Unit = $\ldots$
@@ -678,7 +678,7 @@ println: => Unit $\overload$
```
###### Example
-```
+```scala
def f(x: T): T = $\ldots$
val f = 0
```
@@ -778,25 +778,22 @@ These notions are defined mutually recursively as follows.
## Relations between types
-We define two relations between types.
+We define the following relations between types.
-|Name | Symbolically |Interpretation |
-|-----------------|----------------|-------------------------------------------------|
-|Equivalence |$T \equiv U$ |$T$ and $U$ are interchangeable in all contexts. |
-|Conformance |$T <: U$ |Type $T$ conforms to type $U$. |
+| Name | Symbolically | Interpretation |
+|------------------|----------------|----------------------------------------------------|
+| Equivalence | $T \equiv U$ | $T$ and $U$ are interchangeable in all contexts. |
+| Conformance | $T <: U$ | Type $T$ conforms to ("is a subtype of") type $U$. |
+| Weak Conformance | $T <:_w U$ | Augments conformance for primitive numeric types. |
+| Compatibility | | Type $T$ conforms to type $U$ after conversions. |
### Equivalence
-Equivalence $(\equiv)$ between types is the smallest congruence [^congruence] such that
-the following holds:
+Equivalence $(\equiv)$ between types is the smallest congruence [^congruence] such that the following holds:
-- If $t$ is defined by a type alias `type $t$ = $T$`, then $t$ is
- equivalent to $T$.
-- If a path $p$ has a singleton type `$q$.type`, then
- `$p$.type $\equiv q$.type`.
-- If $O$ is defined by an object definition, and $p$ is a path
- consisting only of package or object selectors and ending in $O$, then
- `$O$.this.type $\equiv p$.type`.
+- If $t$ is defined by a type alias `type $t$ = $T$`, then $t$ is equivalent to $T$.
+- If a path $p$ has a singleton type `$q$.type`, then `$p$.type $\equiv q$.type`.
+- If $O$ is defined by an object definition, and $p$ is a path consisting only of package or object selectors and ending in $O$, then `$O$.this.type $\equiv p$.type`.
- Two [compound types](#compound-types) are equivalent if the sequences
of their component are pairwise equivalent, and occur in the same order, and
their refinements are equivalent. Two refinements are equivalent if they
@@ -827,14 +824,11 @@ the following holds:
### Conformance
-The conformance relation $(<:)$ is the smallest
-transitive relation that satisfies the following conditions.
+The conformance relation $(<:)$ is the smallest transitive relation that satisfies the following conditions.
- Conformance includes equivalence. If $T \equiv U$ then $T <: U$.
- For every value type $T$, `scala.Nothing <: $T$ <: scala.Any`.
-- For every type constructor $T$ (with any number of type parameters),
- `scala.Nothing <: $T$ <: scala.Any`.
-
+- For every type constructor $T$ (with any number of type parameters), `scala.Nothing <: $T$ <: scala.Any`.
- For every class type $T$ such that `$T$ <: scala.AnyRef` one has `scala.Null <: $T$`.
- A type variable or abstract type $t$ conforms to its upper bound and
its lower bound conforms to $t$.
@@ -912,15 +906,12 @@ type $C'$, if one of the following holds.
type declaration `type t[$T_1$ , … , $T_n$] >: L <: U` if
$L <: t <: U$.
-The $(<:)$ relation forms pre-order between types,
-i.e. it is transitive and reflexive. _least upper bounds_ and
-_greatest lower bounds_ of a set of types
-are understood to be relative to that order.
-###### Note
-The least upper bound or greatest lower bound
-of a set of types does not always exist. For instance, consider
-the class definitions
+#### Least upper bounds and greatest lower bounds
+The $(<:)$ relation forms pre-order between types, i.e. it is transitive and reflexive.
+This allows us to define _least upper bounds_ and _greatest lower bounds_ of a set of types in terms of that order.
+The least upper bound or greatest lower bound of a set of types does not always exist.
+For instance, consider the class definitions:
```scala
class A[+T] {}
@@ -949,11 +940,9 @@ free to pick any one of them.
### Weak Conformance
-In some situations Scala uses a more general conformance relation. A
-type $S$ _weakly conforms_
-to a type $T$, written $S <:_w
-T$, if $S <: T$ or both $S$ and $T$ are primitive number types
-and $S$ precedes $T$ in the following ordering.
+In some situations Scala uses a more general conformance relation.
+A type $S$ _weakly conforms_ to a type $T$, written $S <:_w T$,
+if $S <: T$ or both $S$ and $T$ are primitive number types and $S$ precedes $T$ in the following ordering.
```scala
Byte $<:_w$ Short
@@ -964,15 +953,49 @@ Long $<:_w$ Float
Float $<:_w$ Double
```
-A _weak least upper bound_ is a least upper bound with respect to
-weak conformance.
+A _weak least upper bound_ is a least upper bound with respect to weak conformance.
+
+### Compatibility
+A type $T$ is _compatible_ to a type $U$ if $T$ (or its corresponding function type) [weakly conforms](#weak-conformance) to $U$
+after applying [eta-expansion](06-expressions.html#eta-expansion). If $T$ is a method type, it's converted to the corresponding function type. If the types do not weakly conform, the following alternatives are checked in order:
+ - [view application](07-implicits.html#views): there's an implicit view from $T$ to $U$;
+ - dropping by-name modifiers: if $U$ is of the shape `$=> U'$` (and $T$ is not), `$T <:_w U'$`;
+ - SAM conversion: if $T$ corresponds to a function type, and $U$ declares a single abstract method whose type [corresponds](06-expressions.html#sam-conversion) to the function type $U'$, `$T <:_w U'$`.
+
+<!--- TODO: include other implicit conversions in addition to view application?
+
+ trait Proc { def go(x: Any): Unit }
+
+ def foo(x: Any => Unit): Unit = ???
+ def foo(x: Proc): Unit = ???
+
+ foo((x: Any) => 1) // works when you drop either foo overload since value discarding is applied
+
+-->
+
+#### Examples
+
+##### Function compatibility via SAM conversion
+
+Given the definitions
+
+```scala
+def foo(x: Int => String): Unit
+def foo(x: ToString): Unit
+
+trait ToString { def convert(x: Int): String }
+```
+
+The application `foo((x: Int) => x.toString)` [resolves](06-expressions.html#overloading-resolution) to the first overload,
+as it's more specific:
+ - `Int => String` is compatible to `ToString` -- when expecting a value of type `ToString`, you may pass a function literal from `Int` to `String`, as it will be SAM-converted to said function;
+ - `ToString` is not compatible to `Int => String` -- when expecting a function from `Int` to `String`, you may not pass a `ToString`.
## Volatile Types
-Type volatility approximates the possibility that a type parameter or abstract
-type instance
-of a type does not have any non-null values. A value member of a volatile type
-cannot appear in a [path](#paths).
+Type volatility approximates the possibility that a type parameter or
+abstract type instance of a type does not have any non-null values.
+A value member of a volatile type cannot appear in a [path](#paths).
A type is _volatile_ if it falls into one of four categories:
diff --git a/spec/04-basic-declarations-and-definitions.md b/spec/04-basic-declarations-and-definitions.md
index 84459d7639..5e055228f1 100644
--- a/spec/04-basic-declarations-and-definitions.md
+++ b/spec/04-basic-declarations-and-definitions.md
@@ -88,10 +88,10 @@ The class definition `case class X(), Y(n: Int) extends Z` expands to
`case class X extends Z; case class Y(n: Int) extends Z`.
- The object definition `case object Red, Green, Blue extends Color`~
expands to
-```
+```scala
case object Red extends Color
case object Green extends Color
-case object Blue extends Color .
+case object Blue extends Color
```
-->
@@ -144,7 +144,7 @@ value definition `val $p$ = $e$` is expanded as follows:
val $\$ x$ = $e$ match {case $p$ => ($x_1 , \ldots , x_n$)}
val $x_1$ = $\$ x$._1
$\ldots$
-val $x_n$ = $\$ x$._n .
+val $x_n$ = $\$ x$._n
```
Here, $\$ x$ is a fresh name.
@@ -595,9 +595,9 @@ ParamType ::= Type
| Type ‘*’
```
-A function declaration has the form `def $f\,\mathit{psig}$: $T$`, where
+A _function declaration_ has the form `def $f\,\mathit{psig}$: $T$`, where
$f$ is the function's name, $\mathit{psig}$ is its parameter
-signature and $T$ is its result type. A function definition
+signature and $T$ is its result type. A _function definition_
`def $f\,\mathit{psig}$: $T$ = $e$` also includes a _function body_ $e$,
i.e. an expression which defines the function's result. A parameter
signature consists of an optional type parameter clause `[$\mathit{tps}\,$]`,
@@ -612,13 +612,13 @@ result type, if one is given. If the function definition is not
recursive, the result type may be omitted, in which case it is
determined from the packed type of the function body.
-A type parameter clause $\mathit{tps}$ consists of one or more
+A _type parameter clause_ $\mathit{tps}$ consists of one or more
[type declarations](#type-declarations-and-type-aliases), which introduce type
parameters, possibly with bounds. The scope of a type parameter includes
the whole signature, including any of the type parameter bounds as
well as the function body, if it is present.
-A value parameter clause $\mathit{ps}$ consists of zero or more formal
+A _value parameter clause_ $\mathit{ps}$ consists of zero or more formal
parameter bindings such as `$x$: $T$` or `$x: T = e$`, which bind value
parameters and associate them with their types.
@@ -669,6 +669,15 @@ def f(a: Int = 0)(b: Int = a + 1) = b // OK
f(10)() // returns 11 (not 1)
```
+If an [implicit argument](07-implicits.html#implicit-parameters)
+is not found by implicit search, it may be supplied using a default argument.
+
+```scala
+implicit val i: Int = 2
+def f(implicit x: Int, s: String = "hi") = s * x
+f // "hihi"
+```
+
### By-Name Parameters
```ebnf
@@ -774,12 +783,12 @@ FunDef ::= FunSig [nl] ‘{’ Block ‘}’
Special syntax exists for procedures, i.e. functions that return the
`Unit` value `()`.
-A procedure declaration is a function declaration where the result type
+A _procedure declaration_ is a function declaration where the result type
is omitted. 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`.
-A procedure definition is a function definition where the result type
+A _procedure definition_ is a function definition where the result type
and the equals sign are omitted; its defining expression must be a block.
E.g., `def $f$($\mathit{ps}$) {$\mathit{stats}$}` is equivalent to
`def $f$($\mathit{ps}$): Unit = {$\mathit{stats}$}`.
diff --git a/spec/05-classes-and-objects.md b/spec/05-classes-and-objects.md
index 65666e31cb..ffb65979f7 100644
--- a/spec/05-classes-and-objects.md
+++ b/spec/05-classes-and-objects.md
@@ -7,9 +7,9 @@ chapter: 5
# Classes and Objects
```ebnf
-TmplDef ::= [`case'] `class' ClassDef
- | [`case'] `object' ObjectDef
- | `trait' TraitDef
+TmplDef ::= [‘case’] ‘class’ ClassDef
+ | [‘case’] ‘object’ ObjectDef
+ | ‘trait’ TraitDef
```
[Classes](#class-definitions) and [objects](#object-definitions)
@@ -20,14 +20,14 @@ are both defined in terms of _templates_.
```ebnf
ClassTemplate ::= [EarlyDefs] ClassParents [TemplateBody]
TraitTemplate ::= [EarlyDefs] TraitParents [TemplateBody]
-ClassParents ::= Constr {`with' AnnotType}
-TraitParents ::= AnnotType {`with' AnnotType}
-TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `}'
-SelfType ::= id [`:' Type] `=>'
- | this `:' Type `=>'
+ClassParents ::= Constr {‘with’ AnnotType}
+TraitParents ::= AnnotType {‘with’ AnnotType}
+TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’
+SelfType ::= id [‘:’ Type] ‘=>’
+ | this ‘:’ Type ‘=>’
```
-A template defines the type signature, behavior and initial state of a
+A _template_ defines the type signature, behavior and initial state of a
trait or class of objects or of a single object. Templates form part of
instance creation expressions, class definitions, and object
definitions. A template
@@ -145,7 +145,7 @@ def delayedInit(body: => Unit)
### Constructor Invocations
```ebnf
-Constr ::= AnnotType {`(' [Exprs] `)'}
+Constr ::= AnnotType {‘(’ [Exprs] ‘)’}
```
Constructor invocations define the type, members, and initial state of
@@ -344,8 +344,8 @@ $M'$:
- If $M$ and $M'$ are both concrete value definitions, then either none
of them is marked `lazy` or both must be marked `lazy`.
-A stable member can only be overridden by a stable member.
-For example, this is not allowed:
+- A stable member can only be overridden by a stable member.
+ For example, this is not allowed:
```scala
class X { val stable = 1}
@@ -410,7 +410,7 @@ necessary to make subtyping decidable[^kennedy]).
### Early Definitions
```ebnf
-EarlyDefs ::= `{' [EarlyDef {semi EarlyDef}] `}' `with'
+EarlyDefs ::= ‘{’ [EarlyDef {semi EarlyDef}] ‘}’ ‘with’
EarlyDef ::= {Annotation} {Modifier} PatVarDef
```
@@ -478,14 +478,14 @@ body, it would be initialized after the constructor of
```ebnf
Modifier ::= LocalModifier
| AccessModifier
- | `override'
-LocalModifier ::= `abstract'
- | `final'
- | `sealed'
- | `implicit'
- | `lazy'
-AccessModifier ::= (`private' | `protected') [AccessQualifier]
-AccessQualifier ::= `[' (id | `this') `]'
+ | ‘override’
+LocalModifier ::= ‘abstract’
+ | ‘final’
+ | ‘sealed’
+ | ‘implicit’
+ | ‘lazy’
+AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]
+AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
```
Member definitions may be preceded by modifiers which affect the
@@ -597,10 +597,12 @@ overridden in subclasses. A `final` class may not be inherited by
a template. `final` is redundant for object definitions. Members
of final classes or objects are implicitly also final, so the
`final` modifier is generally redundant for them, too. Note, however, that
-[constant value definitions](04-basic-declarations-and-definitions.html#value-declarations-and-definitions) do require
-an explicit `final` modifier, even if they are defined in a final class or
-object. `final` may not be applied to incomplete members, and it may not be
-combined in one modifier list with `sealed`.
+[constant value definitions](04-basic-declarations-and-definitions.html#value-declarations-and-definitions)
+do require an explicit `final` modifier,
+even if they are defined in a final class or object.
+`final` is permitted for abstract classes
+but it may not be applied to traits or incomplete members,
+and it may not be combined in one modifier list with `sealed`.
### `sealed`
The `sealed` modifier applies to class definitions. A
@@ -668,16 +670,16 @@ constructor `private` ([example](#example-private-constructor)).
## Class Definitions
```ebnf
-TmplDef ::= `class' ClassDef
+TmplDef ::= ‘class’ ClassDef
ClassDef ::= id [TypeParamClause] {Annotation}
[AccessModifier] ClassParamClauses ClassTemplateOpt
ClassParamClauses ::= {ClassParamClause}
- [[nl] `(' implicit ClassParams `)']
-ClassParamClause ::= [nl] `(' [ClassParams] ')'
-ClassParams ::= ClassParam {`,' ClassParam}
-ClassParam ::= {Annotation} {Modifier} [(`val' | `var')]
- id [`:' ParamType] [`=' Expr]
-ClassTemplateOpt ::= `extends' ClassTemplate | [[`extends'] TemplateBody]
+ [[nl] ‘(’ implicit ClassParams ‘)’]
+ClassParamClause ::= [nl] ‘(’ [ClassParams] ‘)’
+ClassParams ::= ClassParam {‘,’ ClassParam}
+ClassParam ::= {Annotation} {Modifier} [(‘val’ | ‘var’)]
+ id [‘:’ ParamType] [‘=’ Expr]
+ClassTemplateOpt ::= ‘extends’ ClassTemplate | [[‘extends’] TemplateBody]
```
The most general form of class definition is
@@ -709,7 +711,7 @@ Here,
value parameter may not form part of the types of any of the parent classes or members of the class template $t$.
It is illegal to define two formal value parameters with the same name.
- If no formal parameter sections are given, an empty parameter section `()` is assumed.
+ If a class has no formal parameter section that is not implicit, an empty parameter section `()` is assumed.
If a formal parameter declaration $x: T$ is preceded by a `val`
or `var` keyword, an accessor (getter) [definition](04-basic-declarations-and-definitions.html#variable-declarations-and-definitions)
@@ -725,7 +727,7 @@ Here,
- $t$ is a [template](#templates) of the form
- ```
+ ```scala
$sc$ with $mt_1$ with $\ldots$ with $mt_m$ { $\mathit{stats}$ } // $m \geq 0$
```
@@ -768,12 +770,12 @@ class Sensitive private () {
### Constructor Definitions
```ebnf
-FunDef ::= `this' ParamClause ParamClauses
- (`=' ConstrExpr | [nl] ConstrBlock)
+FunDef ::= ‘this’ ParamClause ParamClauses
+ (‘=’ ConstrExpr | [nl] ConstrBlock)
ConstrExpr ::= SelfInvocation
| ConstrBlock
-ConstrBlock ::= `{' SelfInvocation {semi BlockStat} `}'
-SelfInvocation ::= `this' ArgumentExprs {ArgumentExprs}
+ConstrBlock ::= ‘{’ SelfInvocation {semi BlockStat} ‘}’
+SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}
```
A class may have additional constructors besides the primary
@@ -836,18 +838,19 @@ third one constructs a list with a given head and tail.
### Case Classes
```ebnf
-TmplDef ::= `case' `class' ClassDef
+TmplDef ::= ‘case’ ‘class’ ClassDef
```
If a class definition is prefixed with `case`, the class is said
to be a _case class_.
-The formal parameters in the first parameter section of a case class
-are called _elements_; they are treated
-specially. First, the value of such a parameter can be extracted as a
+A case class is required to have a parameter section that is not implicit.
+The formal parameters in the first parameter section
+are called _elements_ and are treated specially.
+First, the value of such a parameter can be extracted as a
field of a constructor pattern. Second, a `val` prefix is
-implicitly added to such a parameter, unless the parameter carries
-already a `val` or `var` modifier. Hence, an accessor
+implicitly added to such a parameter, unless the parameter already carries
+a `val` or `var` modifier. Hence, an accessor
definition for the parameter is [generated](#class-definitions).
A case class definition of `$c$[$\mathit{tps}\,$]($\mathit{ps}_1\,$)$\ldots$($\mathit{ps}_n$)` with type
@@ -965,12 +968,12 @@ directly extend `Expr` must be in the same source file as
## Traits
```ebnf
-TmplDef ::= `trait' TraitDef
+TmplDef ::= ‘trait’ TraitDef
TraitDef ::= id [TypeParamClause] TraitTemplateOpt
-TraitTemplateOpt ::= `extends' TraitTemplate | [[`extends'] TemplateBody]
+TraitTemplateOpt ::= ‘extends’ TraitTemplate | [[‘extends’] TemplateBody]
```
-A trait is a class that is meant to be added to some other class
+A _trait_ is a class that is meant to be added to some other class
as a mixin. Unlike normal classes, traits cannot have
constructor parameters. Furthermore, no constructor arguments are
passed to the superclass of the trait. This is not necessary as traits are
@@ -1072,7 +1075,7 @@ in `MyTable`.
ObjectDef ::= id ClassTemplate
```
-An object definition defines a single object of a new class. Its
+An _object definition_ defines a single object of a new class. Its
most general form is
`object $m$ extends $t$`. Here,
$m$ is the name of the object to be defined, and
@@ -1101,8 +1104,8 @@ Note that the value defined by an object definition is instantiated
lazily. The `new $m$\$cls` constructor is evaluated
not at the point of the object definition, but is instead evaluated
the first time $m$ is dereferenced during execution of the program
-(which might be never at all). An attempt to dereference $m$ again in
-the course of evaluation of the constructor leads to a infinite loop
+(which might be never at all). An attempt to dereference $m$ again
+during evaluation of the constructor will lead to an infinite loop
or run-time error.
Other threads trying to dereference $m$ while the
constructor is being evaluated block until evaluation is complete.
diff --git a/spec/06-expressions.md b/spec/06-expressions.md
index c24ca01c3b..9e49dfa199 100644
--- a/spec/06-expressions.md
+++ b/spec/06-expressions.md
@@ -7,44 +7,44 @@ chapter: 6
# Expressions
```ebnf
-Expr ::= (Bindings | id | `_') `=>' Expr
+Expr ::= (Bindings | id | ‘_’) ‘=>’ Expr
| Expr1
-Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] `else' Expr]
- | `while' `(' Expr `)' {nl} Expr
- | `try' (`{' Block `}' | Expr) [`catch' `{' CaseClauses `}'] [`finally' Expr]
- | `do' Expr [semi] `while' `(' Expr ')'
- | `for' (`(' Enumerators `)' | `{' Enumerators `}') {nl} [`yield'] Expr
- | `throw' Expr
- | `return' [Expr]
- | [SimpleExpr `.'] id `=' Expr
- | SimpleExpr1 ArgumentExprs `=' Expr
+Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr]
+ | ‘while’ ‘(’ Expr ‘)’ {nl} Expr
+ | ‘try’ (‘{’ Block ‘}’ | Expr) [‘catch’ ‘{’ CaseClauses ‘}’] [‘finally’ Expr]
+ | ‘do’ Expr [semi] ‘while’ ‘(’ Expr ‘)’
+ | ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr
+ | ‘throw’ Expr
+ | ‘return’ [Expr]
+ | [SimpleExpr ‘.’] id ‘=’ Expr
+ | SimpleExpr1 ArgumentExprs ‘=’ Expr
| PostfixExpr
| PostfixExpr Ascription
- | PostfixExpr `match' `{' CaseClauses `}'
+ | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’
PostfixExpr ::= InfixExpr [id [nl]]
InfixExpr ::= PrefixExpr
| InfixExpr id [nl] InfixExpr
-PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr
-SimpleExpr ::= `new' (ClassTemplate | TemplateBody)
+PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr
+SimpleExpr ::= ‘new’ (ClassTemplate | TemplateBody)
| BlockExpr
- | SimpleExpr1 [`_']
+ | SimpleExpr1 [‘_’]
SimpleExpr1 ::= Literal
| Path
- | `_'
- | `(' [Exprs] `)'
- | SimpleExpr `.' id s
+ | ‘_’
+ | ‘(’ [Exprs] ‘)’
+ | SimpleExpr ‘.’ id s
| SimpleExpr TypeArgs
| SimpleExpr1 ArgumentExprs
| XmlExpr
-Exprs ::= Expr {`,' Expr}
+Exprs ::= Expr {‘,’ Expr}
BlockExpr ::= ‘{’ CaseClauses ‘}’
| ‘{’ Block ‘}’
Block ::= BlockStat {semi BlockStat} [ResultExpr]
ResultExpr ::= Expr1
- | (Bindings | ([`implicit'] id | `_') `:' CompoundType) `=>' Block
-Ascription ::= `:' InfixType
- | `:' Annotation {Annotation}
- | `:' `_' `*'
+ | (Bindings | ([‘implicit’] id | ‘_’) ‘:’ CompoundType) ‘=>’ Block
+Ascription ::= ‘:’ InfixType
+ | ‘:’ Annotation {Annotation}
+ | ‘:’ ‘_’ ‘*’
```
Expressions are composed of operators and operands. Expression forms are
@@ -81,10 +81,9 @@ evaluation is immediate.
## The _Null_ Value
-The `null` value is of type `scala.Null`, and is thus
-compatible with every reference type. It denotes a reference value
-which refers to a special “`null`” object. This object
-implements methods in class `scala.AnyRef` as follows:
+The `null` value is of type `scala.Null`, and thus conforms to every reference type.
+It denotes a reference value which refers to a special `null` object.
+This object implements methods in class `scala.AnyRef` as follows:
- `eq($x\,$)` and `==($x\,$)` return `true` iff the
argument $x$ is also the "null" object.
@@ -101,7 +100,7 @@ A reference to any other member of the "null" object causes a
```ebnf
SimpleExpr ::= Path
- | SimpleExpr `.' id
+ | SimpleExpr ‘.’ id
```
A designator refers to a named term. It can be a _simple name_ or
@@ -152,8 +151,8 @@ by a definition overriding $m$.
## This and Super
```ebnf
-SimpleExpr ::= [id `.'] `this'
- | [id '.'] `super' [ClassQualifier] `.' id
+SimpleExpr ::= [id ‘.’] ‘this’
+ | [id ‘.’] ‘super’ [ClassQualifier] ‘.’ id
```
The expression `this` can appear in the statement part of a
@@ -176,7 +175,9 @@ in the least proper supertype of the innermost template containing the
reference. It evaluates to the member $m'$ in the actual supertype of
that template which is equal to $m$ or which overrides $m$. The
statically referenced member $m$ must be a type or a
-method. <!-- explanation: so that we need not create several fields for overriding vals -->
+method.
+
+<!-- explanation: so that we need not create several fields for overriding vals -->
If it is
a method, it must be concrete, or the template
@@ -221,9 +222,14 @@ the linearization of class `D` is `{D, B, A, Root}`.
Then we have:
```scala
-(new A).superA == "Root",
- (new C).superB = "Root", (new C).superC = "B",
-(new D).superA == "Root", (new D).superB = "A", (new D).superD = "B",
+(new A).superA == "Root"
+
+(new C).superB == "Root"
+(new C).superC == "B"
+
+(new D).superA == "Root"
+(new D).superB == "A"
+(new D).superD == "B"
```
Note that the `superB` function returns different results
@@ -233,44 +239,27 @@ depending on whether `B` is mixed in with class `Root` or `A`.
```ebnf
SimpleExpr ::= SimpleExpr1 ArgumentExprs
-ArgumentExprs ::= `(' [Exprs] `)'
- | `(' [Exprs `,'] PostfixExpr `:' `_' `*' ')'
+ArgumentExprs ::= ‘(’ [Exprs] ‘)’
+ | ‘(’ [Exprs ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’
| [nl] BlockExpr
-Exprs ::= Expr {`,' Expr}
-```
-
-An application `$f$($e_1 , \ldots , e_m$)` applies the
-function $f$ to the argument expressions $e_1 , \ldots , e_m$. If $f$
-has a method type `($p_1$:$T_1 , \ldots , p_n$:$T_n$)$U$`, the type of
-each argument expression $e_i$ is typed with the
-corresponding parameter type $T_i$ as expected type. Let $S_i$ be type
-type of argument $e_i$ $(i = 1 , \ldots , m)$. If $f$ is a polymorphic method,
-[local type inference](#local-type-inference) is used to determine
-type arguments for $f$. If $f$ has some value type, the application is taken to
-be equivalent to `$f$.apply($e_1 , \ldots , e_m$)`,
-i.e. the application of an `apply` method defined by $f$.
-
-The function $f$ must be _applicable_ to its arguments $e_1
-, \ldots , e_n$ of types $S_1 , \ldots , S_n$.
-
-If $f$ has a method type $(p_1:T_1 , \ldots , p_n:T_n)U$
-we say that an argument expression $e_i$ is a _named_ argument if
-it has the form $x_i=e'_i$ and $x_i$ is one of the parameter names
-$p_1 , \ldots , p_n$. The function $f$ is applicable if all of the following conditions
-hold:
-
-- For every named argument $x_i=e_i'$ the type $S_i$
- is compatible with the parameter type $T_j$ whose name $p_j$ matches $x_i$.
-- For every positional argument $e_i$ the type $S_i$
-is compatible with $T_i$.
-- If the expected type is defined, the result type $U$ is
- compatible to it.
-
-If $f$ is a polymorphic method it is applicable if
-[local type inference](#local-type-inference) can
-determine type arguments so that the instantiated method is applicable. If
-$f$ has some value type it is applicable if it has a method member named
-`apply` which is applicable.
+Exprs ::= Expr {‘,’ Expr}
+```
+
+An application `$f(e_1 , \ldots , e_m)$` applies the function `$f$` to the argument expressions `$e_1, \ldots , e_m$`. For this expression to be well-typed, the function must be *applicable* to its arguments, which is defined next by case analysis on $f$'s type.
+
+If $f$ has a method type `($p_1$:$T_1 , \ldots , p_n$:$T_n$)$U$`, each argument expression $e_i$ is typed with the corresponding parameter type $T_i$ as expected type. Let $S_i$ be the type of argument $e_i$ $(i = 1 , \ldots , m)$. The function $f$ must be _applicable_ to its arguments $e_1, \ldots , e_n$ of types $S_1 , \ldots , S_n$. We say that an argument expression $e_i$ is a _named_ argument if it has the form `$x_i=e'_i$` and `$x_i$` is one of the parameter names `$p_1, \ldots, p_n$`.
+
+Once the types $S_i$ have been determined, the function $f$ of the above method type is said to be applicable if all of the following conditions hold:
+ - for every named argument $p_j=e_i'$ the type $S_i$ is [compatible](03-types.html#compatibility) with the parameter type $T_j$;
+ - for every positional argument $e_i$ the type $S_i$ is [compatible](03-types.html#compatibility) with $T_i$;
+ - if the expected type is defined, the result type $U$ is [compatible](03-types.html#compatibility) to it.
+
+If $f$ is a polymorphic method, [local type inference](#local-type-inference) is used to instantiate $f$'s type parameters.
+The polymorphic method is applicable if type inference can determine type arguments so that the instantiated method is applicable.
+
+If $f$ has some value type, the application is taken to be equivalent to `$f$.apply($e_1 , \ldots , e_m$)`,
+i.e. the application of an `apply` method defined by $f$. The value `$f$` is applicable to the given arguments if `$f$.apply` is applicable.
+
Evaluation of `$f$($e_1 , \ldots , e_n$)` usually entails evaluation of
$f$ and $e_1 , \ldots , e_n$ in that order. Each argument expression
@@ -336,7 +325,7 @@ would not typecheck.
### Named and Default Arguments
-If an application might uses named arguments $p = e$ or default
+If an application is to use named arguments $p = e$ or default
arguments, the following conditions must hold.
- For every named argument $p_i = e_i$ which appears left of a positional argument
@@ -346,7 +335,7 @@ arguments, the following conditions must hold.
argument defines a parameter which is already specified by a
positional argument.
- Every formal parameter $p_j:T_j$ which is not specified by either a positional
- or a named argument has a default argument.
+ or named argument has a default argument.
If the application uses named or default
arguments the following transformation is applied to convert it into
@@ -422,7 +411,7 @@ On the Java platform version 7 and later, the methods `invoke` and `invokeExact`
## Method Values
```ebnf
-SimpleExpr ::= SimpleExpr1 `_'
+SimpleExpr ::= SimpleExpr1 ‘_’
```
The expression `$e$ _` is well-formed if $e$ is of method
@@ -454,7 +443,7 @@ because otherwise the underscore would be considered part of the name.
SimpleExpr ::= SimpleExpr TypeArgs
```
-A type application `$e$[$T_1 , \ldots , T_n$]` instantiates
+A _type application_ `$e$[$T_1 , \ldots , T_n$]` instantiates
a polymorphic value $e$ of type
`[$a_1$ >: $L_1$ <: $U_1, \ldots , a_n$ >: $L_n$ <: $U_n$]$S$`
with argument types
@@ -471,16 +460,16 @@ $e$.
Type applications can be omitted if
[local type inference](#local-type-inference) can infer best type parameters
-for a polymorphic functions from the types of the actual function arguments
+for a polymorphic function from the types of the actual function arguments
and the expected result type.
## Tuples
```ebnf
-SimpleExpr ::= `(' [Exprs] `)'
+SimpleExpr ::= ‘(’ [Exprs] ‘)’
```
-A tuple expression `($e_1 , \ldots , e_n$)` is an alias
+A _tuple expression_ `($e_1 , \ldots , e_n$)` is an alias
for the class instance creation
`scala.Tuple$n$($e_1 , \ldots , e_n$)`, where $n \geq 2$.
The empty tuple
@@ -489,10 +478,10 @@ The empty tuple
## Instance Creation Expressions
```ebnf
-SimpleExpr ::= `new' (ClassTemplate | TemplateBody)
+SimpleExpr ::= ‘new’ (ClassTemplate | TemplateBody)
```
-A simple instance creation expression is of the form
+A _simple instance creation expression_ is of the form
`new $c$`
where $c$ is a [constructor invocation](05-classes-and-objects.html#constructor-invocations). Let $T$ be
the type of $c$. Then $T$ must
@@ -515,7 +504,7 @@ The expression is evaluated by creating a fresh
object of type $T$ which is initialized by evaluating $c$. The
type of the expression is $T$.
-A general instance creation expression is of the form
+A _general instance creation expression_ is of the form
`new $t$` for some [class template](05-classes-and-objects.html#templates) $t$.
Such an expression is equivalent to the block
@@ -560,7 +549,7 @@ BlockExpr ::= ‘{’ CaseClauses ‘}’
Block ::= BlockStat {semi BlockStat} [ResultExpr]
```
-A block expression `{$s_1$; $\ldots$; $s_n$; $e\,$}` is
+A _block expression_ `{$s_1$; $\ldots$; $s_n$; $e\,$}` is
constructed from a sequence of block statements $s_1 , \ldots , s_n$
and a final expression $e$. The statement sequence may not contain
two definitions or declarations that bind the same name in the same
@@ -621,7 +610,7 @@ the existentially quantified type
PostfixExpr ::= InfixExpr [id [nl]]
InfixExpr ::= PrefixExpr
| InfixExpr id [nl] InfixExpr
-PrefixExpr ::= [`-' | `+' | `!' | `~'] SimpleExpr
+PrefixExpr ::= [‘-’ | ‘+’ | ‘!’ | ‘~’] SimpleExpr
```
Expressions can be constructed from operands and operators.
@@ -671,7 +660,7 @@ precedence, with characters on the same line having the same precedence.
```
That is, operators starting with a letter have lowest precedence,
-followed by operators starting with ``|`', etc.
+followed by operators starting with ‘`|`’, etc.
There's one exception to this rule, which concerns
[_assignment operators_](#assignment-operators).
@@ -680,7 +669,7 @@ of simple assignment `(=)`. That is, it is lower than the
precedence of any other operator.
The _associativity_ of an operator is determined by the operator's
-last character. Operators ending in a colon ``:`' are
+last character. Operators ending in a colon ‘`:`’ are
right-associative. All other operators are left-associative.
Precedence and associativity of operators determine the grouping of
@@ -715,7 +704,7 @@ name.
### Assignment Operators
-An assignment operator is an operator symbol (syntax category
+An _assignment operator_ is an operator symbol (syntax category
`op` in [Identifiers](01-lexical-syntax.html#identifiers)) that ends in an equals character
“`=`”, with the exception of operators for which one of
the following conditions holds:
@@ -751,10 +740,10 @@ The re-interpretation occurs if the following two conditions are fulfilled.
## Typed Expressions
```ebnf
-Expr1 ::= PostfixExpr `:' CompoundType
+Expr1 ::= PostfixExpr ‘:’ CompoundType
```
-The typed expression $e: T$ has type $T$. The type of
+The _typed expression_ $e: T$ has type $T$. The type of
expression $e$ is expected to conform to $T$. The result of
the expression is the value of $e$ converted to type $T$.
@@ -770,18 +759,18 @@ Here are examples of well-typed and ill-typed expressions.
## Annotated Expressions
```ebnf
-Expr1 ::= PostfixExpr `:' Annotation {Annotation}
+Expr1 ::= PostfixExpr ‘:’ Annotation {Annotation}
```
-An annotated expression `$e$: @$a_1$ $\ldots$ @$a_n$`
+An _annotated expression_ `$e$: @$a_1$ $\ldots$ @$a_n$`
attaches [annotations](11-annotations.html#user-defined-annotations) $a_1 , \ldots , a_n$ to the
expression $e$.
## Assignments
```ebnf
-Expr1 ::= [SimpleExpr `.'] id `=' Expr
- | SimpleExpr1 ArgumentExprs `=' Expr
+Expr1 ::= [SimpleExpr ‘.’] id ‘=’ Expr
+ | SimpleExpr1 ArgumentExprs ‘=’ Expr
```
The interpretation of an assignment to a simple variable `$x$ = $e$`
@@ -865,10 +854,10 @@ def matmul(xss: Array[Array[Double]], yss: Array[Array[Double]]) = {
## Conditional Expressions
```ebnf
-Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] `else' Expr]
+Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr]
```
-The conditional expression `if ($e_1$) $e_2$ else $e_3$` chooses
+The _conditional expression_ `if ($e_1$) $e_2$ else $e_3$` chooses
one of the values of $e_2$ and $e_3$, depending on the
value of $e_1$. The condition $e_1$ is expected to
conform to type `Boolean`. The then-part $e_2$ and the
@@ -891,10 +880,10 @@ evaluated as if it was `if ($e_1$) $e_2$ else ()`.
## While Loop Expressions
```ebnf
-Expr1 ::= `while' `(' Expr ')' {nl} Expr
+Expr1 ::= ‘while’ ‘(’ Expr ‘)’ {nl} Expr
```
-The while loop expression `while ($e_1$) $e_2$` is typed and
+The _while loop expression_ `while ($e_1$) $e_2$` is typed and
evaluated as if it was an application of `whileLoop ($e_1$) ($e_2$)` where
the hypothetical function `whileLoop` is defined as follows.
@@ -906,26 +895,26 @@ def whileLoop(cond: => Boolean)(body: => Unit): Unit =
## Do Loop Expressions
```ebnf
-Expr1 ::= `do' Expr [semi] `while' `(' Expr ')'
+Expr1 ::= ‘do’ Expr [semi] ‘while’ ‘(’ Expr ‘)’
```
-The do loop expression `do $e_1$ while ($e_2$)` is typed and
+The _do loop expression_ `do $e_1$ while ($e_2$)` is typed and
evaluated as if it was the expression `($e_1$ ; while ($e_2$) $e_1$)`.
A semicolon preceding the `while` symbol of a do loop expression is ignored.
## For Comprehensions and For Loops
```ebnf
-Expr1 ::= `for' (`(' Enumerators `)' | `{' Enumerators `}')
- {nl} [`yield'] Expr
+Expr1 ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’)
+ {nl} [‘yield’] Expr
Enumerators ::= Generator {semi Generator}
-Generator ::= Pattern1 `<-' Expr {[semi] Guard | semi Pattern1 `=' Expr}
-Guard ::= `if' PostfixExpr
+Generator ::= Pattern1 ‘<-’ Expr {[semi] Guard | semi Pattern1 ‘=’ Expr}
+Guard ::= ‘if’ PostfixExpr
```
-A for loop `for ($\mathit{enums}\,$) $e$` executes expression $e$
-for each binding generated by the enumerators $\mathit{enums}$. A for
-comprehension `for ($\mathit{enums}\,$) yield $e$` evaluates
+A _for loop_ `for ($\mathit{enums}\,$) $e$` executes expression $e$
+for each binding generated by the enumerators $\mathit{enums}$.
+A _for comprehension_ `for ($\mathit{enums}\,$) yield $e$` evaluates
expression $e$ for each binding generated by the enumerators $\mathit{enums}$
and collects the results. An enumerator sequence always starts with a
generator; this can be followed by further generators, value
@@ -961,7 +950,7 @@ comprehensions have been eliminated.
`$e$.foreach { case $p$ => $e'$ }`.
- A for comprehension
- ```
+ ```scala
for ($p$ <- $e$; $p'$ <- $e'; \ldots$) yield $e''$
```
@@ -969,13 +958,13 @@ comprehensions have been eliminated.
sequence of generators, definitions, or guards,
is translated to
- ```
+ ```scala
$e$.flatMap { case $p$ => for ($p'$ <- $e'; \ldots$) yield $e''$ }
```
- A for loop
- ```
+ ```scala
for ($p$ <- $e$; $p'$ <- $e'; \ldots$) $e''$
```
@@ -983,7 +972,7 @@ comprehensions have been eliminated.
sequence of generators, definitions, or guards,
is translated to
- ```
+ ```scala
$e$.foreach { case $p$ => for ($p'$ <- $e'; \ldots$) $e''$ }
```
@@ -996,7 +985,7 @@ comprehensions have been eliminated.
`$p'$ = $e'$` is translated to the following generator of pairs of values, where
$x$ and $x'$ are fresh names:
- ```
+ ```scala
($p$, $p'$) <- for ($x @ p$ <- $e$) yield { val $x' @ p'$ = $e'$; ($x$, $x'$) }
```
@@ -1064,10 +1053,10 @@ The code above makes use of the fact that `map`, `flatMap`,
## Return Expressions
```ebnf
-Expr1 ::= `return' [Expr]
+Expr1 ::= ‘return’ [Expr]
```
-A return expression `return $e$` must occur inside the body of some
+A _return expression_ `return $e$` must occur inside the body of some
enclosing named method or function. The innermost enclosing named
method or function in a source program, $f$, must have an explicitly declared result type,
and the type of $e$ must conform to it.
@@ -1101,10 +1090,10 @@ and will propagate up the call stack.
## Throw Expressions
```ebnf
-Expr1 ::= `throw' Expr
+Expr1 ::= ‘throw’ Expr
```
-A throw expression `throw $e$` evaluates the expression
+A _throw expression_ `throw $e$` evaluates the expression
$e$. The type of this expression must conform to
`Throwable`. If $e$ evaluates to an exception
reference, evaluation is aborted with the thrown exception. If $e$
@@ -1118,11 +1107,11 @@ is `scala.Nothing`.
## Try Expressions
```ebnf
-Expr1 ::= `try' (`{' Block `}' | Expr) [`catch' `{' CaseClauses `}']
- [`finally' Expr]
+Expr1 ::= ‘try’ (‘{’ Block ‘}’ | Expr) [‘catch’ ‘{’ CaseClauses ‘}’]
+ [‘finally’ Expr]
```
-A try expression is of the form `try { $b$ } catch $h$`
+A _try expression_ is of the form `try { $b$ } catch $h$`
where the handler $h$ is a
[pattern matching anonymous function](08-pattern-matching.html#pattern-matching-anonymous-functions)
@@ -1141,11 +1130,9 @@ re-thrown.
Let $\mathit{pt}$ be the expected type of the try expression. The block
$b$ is expected to conform to $\mathit{pt}$. The handler $h$
-is expected conform to type
-`scala.PartialFunction[scala.Throwable, $\mathit{pt}\,$]`. The
-type of the try expression is the [weak least upper bound](03-types.html#weak-conformance)
-of the type of $b$
-and the result type of $h$.
+is expected conform to type `scala.PartialFunction[scala.Throwable, $\mathit{pt}\,$]`.
+The type of the try expression is the [weak least upper bound](03-types.html#weak-conformance)
+of the type of $b$ and the result type of $h$.
A try expression `try { $b$ } finally $e$` evaluates the block
$b$. If evaluation of $b$ does not cause an exception to be
@@ -1172,32 +1159,32 @@ for `try { try { $b$ } catch $e_1$ } finally $e_2$`.
## Anonymous Functions
```ebnf
-Expr ::= (Bindings | [`implicit'] id | `_') `=>' Expr
-ResultExpr ::= (Bindings | ([`implicit'] id | `_') `:' CompoundType) `=>' Block
-Bindings ::= `(' Binding {`,' Binding} `)'
-Binding ::= (id | `_') [`:' Type]
-```
-
-The anonymous function `($x_1$: $T_1 , \ldots , x_n$: $T_n$) => e`
-maps parameters $x_i$ of types $T_i$ to a result given
-by expression $e$. The scope of each formal parameter
-$x_i$ is $e$. Formal parameters must have pairwise distinct names.
-
-If the expected type of the anonymous function is of the form
-`scala.Function$n$[$S_1 , \ldots , S_n$, $R\,$]`, the
-expected type of $e$ is $R$ and the type $T_i$ of any of the
-parameters $x_i$ can be omitted, in which
-case`$T_i$ = $S_i$` is assumed.
-If the expected type of the anonymous function is
-some other type, all formal parameter types must be explicitly given,
-and the expected type of $e$ is undefined. The type of the anonymous
-function
-is`scala.Function$n$[$S_1 , \ldots , S_n$, $T\,$]`,
-where $T$ is the [packed type](#expression-typing)
-of $e$. $T$ must be equivalent to a
-type which does not refer to any of the formal parameters $x_i$.
-
-The anonymous function is evaluated as the instance creation expression
+Expr ::= (Bindings | [‘implicit’] id | ‘_’) ‘=>’ Expr
+ResultExpr ::= (Bindings | ([‘implicit’] id | ‘_’) ‘:’ CompoundType) ‘=>’ Block
+Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’
+Binding ::= (id | ‘_’) [‘:’ Type]
+```
+
+The anonymous function of arity $n$, `($x_1$: $T_1 , \ldots , x_n$: $T_n$) => e` maps parameters $x_i$ of types $T_i$ to a result given by expression $e$. The scope of each formal parameter $x_i$ is $e$. Formal parameters must have pairwise distinct names.
+
+In the case of a single untyped formal parameter, `($x\,$) => $e$` can be abbreviated to `$x$ => $e$`. If an anonymous function `($x$: $T\,$) => $e$` with a single typed parameter appears as the result expression of a block, it can be abbreviated to `$x$: $T$ => e`.
+
+A formal parameter may also be a wildcard represented by an underscore `_`. In that case, a fresh name for the parameter is chosen arbitrarily.
+
+A named parameter of an anonymous function may be optionally preceded by an `implicit` modifier. In that case the parameter is labeled [`implicit`](07-implicits.html#implicit-parameters-and-views); however the parameter section itself does not count as an [implicit parameter section](07-implicits.html#implicit-parameters). Hence, arguments to anonymous functions always have to be given explicitly.
+
+### Translation
+If the expected type of the anonymous function is of the shape `scala.Function$n$[$S_1 , \ldots , S_n$, $R\,$]`, or can be [SAM-converted](#sam-conversion) to such a function type, the type `$T_i$` of a parameter `$x_i$` can be omitted, as far as `$S_i$` is defined in the expected type, and `$T_i$ = $S_i$` is assumed. Furthermore, the expected type when type checking $e$ is $R$.
+
+If there is no expected type for the function literal, all formal parameter types `$T_i$` must be specified explicitly, and the expected type of $e$ is undefined. The type of the anonymous function is `scala.Function$n$[$T_1 , \ldots , T_n$, $R\,$]`, where $R$ is the [packed type](#expression-typing) of $e$. $R$ must be equivalent to a type which does not refer to any of the formal parameters $x_i$.
+
+The eventual run-time value of an anonymous function is determined by the expected type:
+ - a subclass of one of the builtin function types, `scala.Function$n$[$S_1 , \ldots , S_n$, $R\,$]` (with $S_i$ and $R$ fully defined),
+ - a [single-abstract-method (SAM) type](#sam-conversion);
+ - `PartialFunction[$T$, $U$]`, if the function literal is of the shape `x => x match { $\ldots$ }`
+ - some other type.
+
+The standard anonymous function evaluates in the same way as the following instance creation expression:
```scala
new scala.Function$n$[$T_1 , \ldots , T_n$, $T$] {
@@ -1205,22 +1192,11 @@ new scala.Function$n$[$T_1 , \ldots , T_n$, $T$] {
}
```
-In the case of a single untyped formal parameter,
-`($x\,$) => $e$`
-can be abbreviated to `$x$ => $e$`. If an
-anonymous function `($x$: $T\,$) => $e$` with a single
-typed parameter appears as the result expression of a block, it can be
-abbreviated to `$x$: $T$ => e`.
+The same evaluation holds for a SAM type, except that the instantiated type is given by the SAM type, and the implemented method is the single abstract method member of this type.
-A formal parameter may also be a wildcard represented by an underscore `_`.
-In that case, a fresh name for the parameter is chosen arbitrarily.
+The underlying platform may provide more efficient ways of constructing these instances, such as Java 8's `invokedynamic` bytecode and `LambdaMetaFactory` class.
-A named parameter of an anonymous function may be optionally preceded
-by an `implicit` modifier. In that case the parameter is
-labeled [`implicit`](07-implicits.html#implicit-parameters-and-views); however the
-parameter section itself does not count as an implicit parameter
-section in the sense defined [here](07-implicits.html#implicit-parameters). Hence, arguments to
-anonymous functions always have to be given explicitly.
+A `PartialFunction`'s value receives an additional `isDefinedAt` member, which is derived from the pattern match in the function literal, with each case's body being replaced by `true`, and an added default (if none was given) that evaluates to `false`.
###### Example
Examples of anonymous functions:
@@ -1244,7 +1220,7 @@ _ => 5 // The function that ignores its argument
### Placeholder Syntax for Anonymous Functions
```ebnf
-SimpleExpr1 ::= `_'
+SimpleExpr1 ::= ‘_’
```
An expression (of syntactic category `Expr`)
@@ -1290,11 +1266,9 @@ include at least the expressions of the following forms:
- A string literal
- A class constructed with [`Predef.classOf`](12-the-scala-standard-library.html#the-predef-object)
- An element of an enumeration from the underlying platform
-- A literal array, of the form
- `Array$(c_1 , \ldots , c_n)$`,
+- A literal array, of the form `Array$(c_1 , \ldots , c_n)$`,
where all of the $c_i$'s are themselves constant expressions
-- An identifier defined by a
- [constant value definition](04-basic-declarations-and-definitions.html#value-declarations-and-definitions).
+- An identifier defined by a [constant value definition](04-basic-declarations-and-definitions.html#value-declarations-and-definitions).
## Statements
@@ -1311,7 +1285,7 @@ TemplateStat ::= Import
|
```
-Statements occur as parts of blocks and templates. A statement can be
+Statements occur as parts of blocks and templates. A _statement_ can be
an import, a definition or an expression, or it can be empty.
Statements used in the template of a class definition can also be
declarations. An expression that is used as a statement can have an
@@ -1335,10 +1309,6 @@ Implicit conversions can be applied to expressions whose type does not
match their expected type, to qualifiers in selections, and to unapplied methods. The
available implicit conversions are given in the next two sub-sections.
-We say, a type $T$ is _compatible_ to a type $U$ if $T$ weakly conforms
-to $U$ after applying [eta-expansion](#eta-expansion) and
-[view applications](07-implicits.html#views).
-
### Value Conversions
The following seven implicit conversions can be applied to an
@@ -1382,12 +1352,36 @@ If $e$ has some value type and the expected type is `Unit`,
$e$ is converted to the expected type by embedding it in the
term `{ $e$; () }`.
+###### SAM conversion
+An expression `(p1, ..., pN) => body` of function type `(T1, ..., TN) => T` is sam-convertible to the expected type `S` if the following holds:
+ - the class `C` of `S` declares an abstract method `m` with signature `(p1: A1, ..., pN: AN): R`;
+ - besides `m`, `C` must not declare or inherit any other deferred value members;
+ - the method `m` must have a single argument list;
+ - there must be a type `U` that is a subtype of `S`, so that the expression
+ `new U { final def m(p1: A1, ..., pN: AN): R = body }` is well-typed (conforming to the expected type `S`);
+ - for the purpose of scoping, `m` should be considered a static member (`U`'s members are not in scope in `body`);
+ - `(A1, ..., AN) => R` is a subtype of `(T1, ..., TN) => T` (satisfying this condition drives type inference of unknown type parameters in `S`);
+
+Note that a function literal that targets a SAM is not necessarily compiled to the above instance creation expression. This is platform-dependent.
+
+It follows that:
+ - if class `C` defines a constructor, it must be accessible and must define exactly one, empty, argument list;
+ - class `C` cannot be `final` or `sealed` (for simplicity we ignore the possibility of SAM conversion in the same compilation unit as the sealed class);
+ - `m` cannot be polymorphic;
+ - it must be possible to derive a fully-defined type `U` from `S` by inferring any unknown type parameters of `C`.
+
+Finally, we impose some implementation restrictions (these may be lifted in future releases):
+ - `C` must not be nested or local (it must not capture its environment, as that results in a zero-argument constructor)
+ - `C`'s constructor must not have an implicit argument list (this simplifies type inference);
+ - `C` must not declare a self type (this simplifies type inference);
+ - `C` must not be `@specialized`.
+
###### View Application
If none of the previous conversions applies, and $e$'s type
does not conform to the expected type $\mathit{pt}$, it is attempted to convert
$e$ to the expected type with a [view](07-implicits.html#views).
-###### Dynamic Member Selection
+###### Selection on `Dynamic`
If none of the previous conversions applies, and $e$ is a prefix
of a selection $e.x$, and $e$'s type conforms to class `scala.Dynamic`,
then the selection is rewritten according to the rules for
@@ -1426,34 +1420,36 @@ a function. Let $\mathscr{A}$ be the set of members referenced by $e$.
Assume first that $e$ appears as a function in an application, as in
`$e$($e_1 , \ldots , e_m$)`.
-One first determines the set of functions that is potentially
-applicable based on the _shape_ of the arguments.
+One first determines the set of functions that is potentially [applicable](#function-applications)
+based on the _shape_ of the arguments.
-The shape of an argument expression $e$, written $\mathit{shape}(e)$, is
+The *shape* of an argument expression $e$, written $\mathit{shape}(e)$, is
a type that is defined as follows:
+ - For a function expression `($p_1$: $T_1 , \ldots , p_n$: $T_n$) => $b$: (Any $, \ldots ,$ Any) => $\mathit{shape}(b)$`,
+ where `Any` occurs $n$ times in the argument type.
+ - For a named argument `$n$ = $e$`: $\mathit{shape}(e)$.
+ - For all other expressions: `Nothing`.
+
+Let $\mathscr{B}$ be the set of alternatives in $\mathscr{A}$ that are [_applicable_](#function-applications)
+to expressions $(e_1 , \ldots , e_n)$ of types $(\mathit{shape}(e_1) , \ldots , \mathit{shape}(e_n))$.
+If there is precisely one alternative in $\mathscr{B}$, that alternative is chosen.
+
+Otherwise, let $S_1 , \ldots , S_m$ be the list of types obtained by typing each argument as follows.
+An argument `$e_i$` of the shape `($p_1$: $T_1 , \ldots , p_n$: $T_n$) => $b$` where one of the `$T_i$` is missing,
+i.e., a function literal with a missing parameter type, is typed with an expected function type that
+propagates the least upper bound of the fully defined types of the corresponding parameters of
+the ([SAM-converted](#sam-conversion)) function types specified by the `$i$`th argument type found in each alternative.
+All other arguments are typed with an undefined expected type.
+
+For every member $m$ in $\mathscr{B}$ one determines whether it is applicable
+to expressions ($e_1 , \ldots , e_m$) of types $S_1, \ldots , S_m$.
-- For a function expression `($p_1$: $T_1 , \ldots , p_n$: $T_n$) => $b$`:
- `(Any $, \ldots ,$ Any) => $\mathit{shape}(b)$`, where `Any` occurs $n$ times
- in the argument type.
-- For a named argument `$n$ = $e$`: $\mathit{shape}(e)$.
-- For all other expressions: `Nothing`.
-
-Let $\mathscr{B}$ be the set of alternatives in $\mathscr{A}$ that are
-[_applicable_](#function-applications)
-to expressions $(e_1 , \ldots , e_n)$ of types
-$(\mathit{shape}(e_1) , \ldots , \mathit{shape}(e_n))$.
-If there is precisely one
-alternative in $\mathscr{B}$, that alternative is chosen.
-
-Otherwise, let $S_1 , \ldots , S_m$ be the vector of types obtained by
-typing each argument with an undefined expected type. For every
-member $m$ in $\mathscr{B}$ one determines whether it is
-applicable to expressions ($e_1 , \ldots , e_m$) of types $S_1
-, \ldots , S_m$.
It is an error if none of the members in $\mathscr{B}$ is applicable. If there is one
single applicable alternative, that alternative is chosen. Otherwise, let $\mathscr{CC}$
be the set of applicable alternatives which don't employ any default argument
-in the application to $e_1 , \ldots , e_m$. It is again an error if $\mathscr{CC}$ is empty.
+in the application to $e_1 , \ldots , e_m$.
+
+It is again an error if $\mathscr{CC}$ is empty.
Otherwise, one chooses the _most specific_ alternative among the alternatives
in $\mathscr{CC}$, according to the following definition of being "as specific as", and
"more specific than":
@@ -1469,21 +1465,17 @@ question: given
so the method is not more specific than the value.
-->
-- A parameterized method $m$ of type `($p_1:T_1, \ldots , p_n:T_n$)$U$` is _as specific as_ some other
- member $m'$ of type $S$ if $m'$ is applicable to arguments
- `($p_1 , \ldots , p_n\,$)` of
- types $T_1 , \ldots , T_n$.
-- A polymorphic method of type
- `[$a_1$ >: $L_1$ <: $U_1 , \ldots , a_n$ >: $L_n$ <: $U_n$]$T$` is
- as specific as some other member of type $S$ if $T$ is as
- specific as $S$ under the assumption that for
- $i = 1 , \ldots , n$ each $a_i$ is an abstract type name
+- A parameterized method $m$ of type `($p_1:T_1, \ldots , p_n:T_n$)$U$` is
+ _as specific as_ some other member $m'$ of type $S$ if $m'$ is [applicable](#function-applications)
+ to arguments `($p_1 , \ldots , p_n$)` of types $T_1 , \ldots , T_n$.
+- A polymorphic method of type `[$a_1$ >: $L_1$ <: $U_1 , \ldots , a_n$ >: $L_n$ <: $U_n$]$T$` is
+ as specific as some other member of type $S$ if $T$ is as specific as $S$
+ under the assumption that for $i = 1 , \ldots , n$ each $a_i$ is an abstract type name
bounded from below by $L_i$ and from above by $U_i$.
-- A member of any other type is always as specific as a parameterized method
- or a polymorphic method.
-- Given two members of types $T$ and $U$ which are
- neither parameterized nor polymorphic method types, the member of type $T$ is as specific as
- the member of type $U$ if the existential dual of $T$ conforms to the existential dual of $U$.
+- A member of any other type is always as specific as a parameterized method or a polymorphic method.
+- Given two members of types $T$ and $U$ which are neither parameterized nor polymorphic method types,
+ the member of type $T$ is as specific as the member of type $U$ if
+ the existential dual of $T$ conforms to the existential dual of $U$.
Here, the existential dual of a polymorphic type
`[$a_1$ >: $L_1$ <: $U_1 , \ldots , a_n$ >: $L_n$ <: $U_n$]$T$` is
`$T$ forSome { type $a_1$ >: $L_1$ <: $U_1$ $, \ldots ,$ type $a_n$ >: $L_n$ <: $U_n$}`.
@@ -1493,8 +1485,7 @@ The _relative weight_ of an alternative $A$ over an alternative $B$ is a
number from 0 to 2, defined as the sum of
- 1 if $A$ is as specific as $B$, 0 otherwise, and
-- 1 if $A$ is defined in a class or object which is derived
- from the class or object defining $B$, 0 otherwise.
+- 1 if $A$ is defined in a class or object which is derived from the class or object defining $B$, 0 otherwise.
A class or object $C$ is _derived_ from a class or object $D$ if one of
the following holds:
@@ -1517,15 +1508,13 @@ arguments in $\mathit{targs}$ are chosen. It is an error if no such alternative
If there are several such alternatives, overloading resolution is
applied again to the whole expression `$e$[$\mathit{targs}\,$]`.
-Assume finally that $e$ does not appear as a function in either
-an application or a type application. If an expected type is given,
-let $\mathscr{B}$ be the set of those alternatives in $\mathscr{A}$ which are
-[compatible](#implicit-conversions) to it. Otherwise, let $\mathscr{B}$ be the same
-as $\mathscr{A}$.
-We choose in this case the most specific alternative among all
-alternatives in $\mathscr{B}$. It is an error if there is no
-alternative in $\mathscr{B}$ which is more specific than all other
-alternatives in $\mathscr{B}$.
+Assume finally that $e$ does not appear as a function in either an application or a type application.
+If an expected type is given, let $\mathscr{B}$ be the set of those alternatives
+in $\mathscr{A}$ which are [compatible](03-types.html#compatibility) to it.
+Otherwise, let $\mathscr{B}$ be the same as $\mathscr{A}$.
+In this last case we choose the most specific alternative among all alternatives in $\mathscr{B}$.
+It is an error if there is no alternative in $\mathscr{B}$ which is
+more specific than all other alternatives in $\mathscr{B}$.
###### Example
Consider the following definitions:
@@ -1552,9 +1541,8 @@ no most specific applicable signature exists.
### Local Type Inference
Local type inference infers type arguments to be passed to expressions
-of polymorphic type. Say $e$ is of type [$a_1$ >: $L_1$ <: $U_1
-, \ldots , a_n$ >: $L_n$ <: $U_n$]$T$ and no explicit type parameters
-are given.
+of polymorphic type. Say $e$ is of type [$a_1$ >: $L_1$ <: $U_1, \ldots , a_n$ >: $L_n$ <: $U_n$]$T$
+and no explicit type parameters are given.
Local type inference converts this expression to a type
application `$e$[$T_1 , \ldots , T_n$]`. The choice of the
diff --git a/spec/07-implicits.md b/spec/07-implicits.md
index 28f6dfe5a8..b0c8c1da24 100644
--- a/spec/07-implicits.md
+++ b/spec/07-implicits.md
@@ -44,7 +44,7 @@ object Monoids {
## Implicit Parameters
-An implicit parameter list
+An _implicit parameter list_
`(implicit $p_1$,$\ldots$,$p_n$)` of a method marks the parameters $p_1 , \ldots , p_n$ as
implicit. A method or constructor can have only one implicit parameter
list, and it must be the last parameter list given.
@@ -155,7 +155,7 @@ sort(yss)
The call above will be completed by passing two nested implicit arguments:
```scala
-sort(yss)(xs: List[Int] => list2ordered[Int](xs)(int2ordered)) .
+sort(yss)(xs: List[Int] => list2ordered[Int](xs)(int2ordered))
```
The possibility of passing implicit arguments to implicit arguments
@@ -218,7 +218,7 @@ which implicit arguments are searched is
```scala
List[List[Int]] => Ordered[List[List[Int]]],
-List[Int] => Ordered[List[Int]]
+List[Int] => Ordered[List[Int]],
Int => Ordered[Int]
```
@@ -290,7 +290,7 @@ or the call-by-name category).
Class `scala.Ordered[A]` contains a method
```scala
- def <= [B >: A](that: B)(implicit b2ordered: B => Ordered[B]): Boolean .
+ def <= [B >: A](that: B)(implicit b2ordered: B => Ordered[B]): Boolean
```
Assume two lists `xs` and `ys` of type `List[Int]`
diff --git a/spec/08-pattern-matching.md b/spec/08-pattern-matching.md
index d496388a91..ecaaa04c2b 100644
--- a/spec/08-pattern-matching.md
+++ b/spec/08-pattern-matching.md
@@ -10,10 +10,10 @@ chapter: 8
```ebnf
Pattern ::= Pattern1 { ‘|’ Pattern1 }
- Pattern1 ::= varid ‘:’ TypePat
+ Pattern1 ::= boundvarid ‘:’ TypePat
| ‘_’ ‘:’ TypePat
| Pattern2
- Pattern2 ::= varid [‘@’ Pattern3]
+ Pattern2 ::= id [‘@’ Pattern3]
| Pattern3
Pattern3 ::= SimplePattern
| SimplePattern {id [nl] SimplePattern}
@@ -22,7 +22,7 @@ chapter: 8
| Literal
| StableId
| StableId ‘(’ [Patterns] ‘)’
- | StableId ‘(’ [Patterns ‘,’] [varid ‘@’] ‘_’ ‘*’ ‘)’
+ | StableId ‘(’ [Patterns ‘,’] [id ‘@’] ‘_’ ‘*’ ‘)’
| ‘(’ [Patterns] ‘)’
| XmlPattern
Patterns ::= Pattern {‘,’ Patterns}
@@ -56,11 +56,11 @@ patterns.
### Variable Patterns
```ebnf
- SimplePattern ::= `_'
+ SimplePattern ::= ‘_’
| varid
```
-A variable pattern $x$ is a simple identifier which starts with a
+A _variable pattern_ $x$ is a simple identifier which starts with a
lower case letter. It matches any value, and binds the variable name
to that value. The type of $x$ is the expected type of the pattern as
given from outside. A special case is the wild-card pattern `_`
@@ -69,11 +69,11 @@ which is treated as if it was a fresh variable on each occurrence.
### Typed Patterns
```ebnf
- Pattern1 ::= varid `:' TypePat
- | `_' `:' TypePat
+ Pattern1 ::= varid ‘:’ TypePat
+ | ‘_’ ‘:’ TypePat
```
-A typed pattern $x: T$ consists of a pattern variable $x$ and a
+A _typed pattern_ $x: T$ consists of a pattern variable $x$ and a
type pattern $T$. The type of $x$ is the type pattern $T$, where
each type variable and wildcard is replaced by a fresh, unknown type.
This pattern matches any value matched by the [type pattern](#type-patterns)
@@ -83,10 +83,10 @@ that value.
### Pattern Binders
```ebnf
- Pattern2 ::= varid `@' Pattern3
+ Pattern2 ::= varid ‘@’ Pattern3
```
-A pattern binder `$x$@$p$` consists of a pattern variable $x$ and a
+A _pattern binder_ `$x$@$p$` consists of a pattern variable $x$ and a
pattern $p$. The type of the variable $x$ is the static type $T$ of the pattern $p$.
This pattern matches any value $v$ matched by the pattern $p$,
provided the run-time type of $v$ is also an instance of $T$,
@@ -98,7 +98,7 @@ and it binds the variable name to that value.
SimplePattern ::= Literal
```
-A literal pattern $L$ matches any value that is equal (in terms of
+A _literal pattern_ $L$ matches any value that is equal (in terms of
`==`) to the literal $L$. The type of $L$ must conform to the
expected type of the pattern.
@@ -108,7 +108,7 @@ expected type of the pattern.
SimplePattern ::= StableId
```
-A stable identifier pattern is a [stable identifier](03-types.html#paths) $r$.
+A _stable identifier pattern_ is a [stable identifier](03-types.html#paths) $r$.
The type of $r$ must conform to the expected
type of the pattern. The pattern matches any value $v$ such that
`$r$ == $v$` (see [here](12-the-scala-standard-library.html#root-classes)).
@@ -144,10 +144,10 @@ argument of `f` are equal.
### Constructor Patterns
```ebnf
-SimplePattern ::= StableId `(' [Patterns] `)
+SimplePattern ::= StableId ‘(’ [Patterns] ‘)’
```
-A constructor pattern is of the form $c(p_1 , \ldots , p_n)$ where $n
+A _constructor pattern_ is of the form $c(p_1 , \ldots , p_n)$ where $n
\geq 0$. It consists of a stable identifier $c$, followed by element
patterns $p_1 , \ldots , p_n$. The constructor $c$ is a simple or
qualified name which denotes a [case class](05-classes-and-objects.html#case-classes).
@@ -170,10 +170,10 @@ repeated parameter. This is further discussed [here](#pattern-sequences).
### Tuple Patterns
```ebnf
- SimplePattern ::= `(' [Patterns] `)'
+ SimplePattern ::= ‘(’ [Patterns] ‘)’
```
-A tuple pattern `($p_1 , \ldots , p_n$)` is an alias
+A _tuple pattern_ `($p_1 , \ldots , p_n$)` is an alias
for the constructor pattern `scala.Tuple$n$($p_1 , \ldots , p_n$)`,
where $n \geq 2$. The empty tuple
`()` is the unique value of type `scala.Unit`.
@@ -181,10 +181,10 @@ where $n \geq 2$. The empty tuple
### Extractor Patterns
```ebnf
- SimplePattern ::= StableId `(' [Patterns] `)'
+ SimplePattern ::= StableId ‘(’ [Patterns] ‘)’
```
-An extractor pattern $x(p_1 , \ldots , p_n)$ where $n \geq 0$ is of
+An _extractor pattern_ $x(p_1 , \ldots , p_n)$ where $n \geq 0$ is of
the same syntactic form as a constructor pattern. However, instead of
a case class, the stable identifier $x$ denotes an object which has a
member method named `unapply` or `unapplySeq` that matches
@@ -241,10 +241,10 @@ val y = x match {
### Pattern Sequences
```ebnf
-SimplePattern ::= StableId `(' [Patterns `,'] [varid `@'] `_' `*' `)'
+SimplePattern ::= StableId ‘(’ [Patterns ‘,’] [varid ‘@’] ‘_’ ‘*’ ‘)’
```
-A pattern sequence $p_1 , \ldots , p_n$ appears in two contexts.
+A _pattern sequence_ $p_1 , \ldots , p_n$ appears in two contexts.
First, in a constructor pattern $c(q_1 , \ldots , q_m, p_1 , \ldots , p_n)$, where $c$ is a case class which has $m+1$ primary constructor parameters, ending in a [repeated parameter](04-basic-declarations-and-definitions.html#repeated-parameters) of type `S*`.
Second, in an extractor pattern $x(q_1 , \ldots , q_m, p_1 , \ldots , p_n)$ if the extractor object $x$ does not have an `unapply` method,
but it does define an `unapplySeq` method with a result type conforming to `Option[(T_1, ... , T_m, Seq[S])]` (if `m = 0`, the type `Option[Seq[S]]` is also accepted). The expected type for the patterns $p_i$ is $S$.
@@ -265,7 +265,7 @@ p_n$.
Pattern3 ::= SimplePattern {id [nl] SimplePattern}
```
-An infix operation pattern $p;\mathit{op};q$ is a shorthand for the
+An _infix operation pattern_ $p;\mathit{op};q$ is a shorthand for the
constructor or extractor pattern $\mathit{op}(p, q)$. The precedence and
associativity of operators in patterns is the same as in
[expressions](06-expressions.html#prefix,-infix,-and-postfix-operations).
@@ -277,10 +277,10 @@ shorthand for the constructor or extractor pattern $\mathit{op}(p, q_1
### Pattern Alternatives
```ebnf
- Pattern ::= Pattern1 { `|' Pattern1 }
+ Pattern ::= Pattern1 { ‘|’ Pattern1 }
```
-A pattern alternative `$p_1$ | $\ldots$ | $p_n$`
+A _pattern alternative_ `$p_1$ | $\ldots$ | $p_n$`
consists of a number of alternative patterns $p_i$. All alternative
patterns are type checked with the expected type of the pattern. They
may not bind variables other than wildcards. The alternative pattern
@@ -328,10 +328,12 @@ A type pattern $T$ is of one of the following forms:
* A reference to a class $C$, $p.C$, or `$T$#$C$`. This
type pattern matches any non-null instance of the given class.
- Note that the prefix of the class, if it is given, is relevant for determining
+ Note that the prefix of the class, if it exists, is relevant for determining
class instances. For instance, the pattern $p.C$ matches only
instances of classes $C$ which were created with the path $p$ as
- prefix.
+ prefix. This also applies to prefixes which are not given syntactically.
+ For example, if $C$ refers to a class defined in the nearest enclosing
+ class and is thus equivalent to $this.C$, it is considered to have a prefix.
The bottom types `scala.Nothing` and `scala.Null` cannot
be used as type patterns, because they would match nothing in any case.
@@ -439,7 +441,7 @@ complexity.
### Type parameter inference for constructor patterns
Assume a constructor pattern $C(p_1 , \ldots , p_n)$ where class $C$
-has type type parameters $a_1 , \ldots , a_n$. These type parameters
+has type parameters $a_1 , \ldots , a_n$. These type parameters
are inferred in the same way as for the typed pattern
`(_: $C[a_1 , \ldots , a_n]$)`.
@@ -519,12 +521,12 @@ function's declared result type, `Number`.
## Pattern Matching Expressions
```ebnf
- Expr ::= PostfixExpr `match' `{' CaseClauses `}'
+ Expr ::= PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’
CaseClauses ::= CaseClause {CaseClause}
- CaseClause ::= `case' Pattern [Guard] `=>' Block
+ CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block
```
-A pattern matching expression
+A _pattern matching expression_
```scala
e match { case $p_1$ => $b_1$ $\ldots$ case $p_n$ => $b_n$ }
@@ -636,7 +638,7 @@ conforms to its expected type, `T`.
## Pattern Matching Anonymous Functions
```ebnf
- BlockExpr ::= `{' CaseClauses `}'
+ BlockExpr ::= ‘{’ CaseClauses ‘}’
```
An anonymous function can be defined by a sequence of cases
@@ -652,7 +654,8 @@ or `scala.PartialFunction[$S_1$, $R$]`, where the
argument type(s) $S_1 , \ldots , S_k$ must be fully determined, but the result type
$R$ may be undetermined.
-If the expected type is `scala.Function$k$[$S_1 , \ldots , S_k$, $R$]`,
+If the expected type is [SAM-convertible](06-expressions.html#sam-conversion)
+to `scala.Function$k$[$S_1 , \ldots , S_k$, $R$]`,
the expression is taken to be equivalent to the anonymous function:
```scala
diff --git a/spec/09-top-level-definitions.md b/spec/09-top-level-definitions.md
index b8a8dc7e0a..1c2f7ec85e 100644
--- a/spec/09-top-level-definitions.md
+++ b/spec/09-top-level-definitions.md
@@ -23,7 +23,7 @@ A compilation unit consists of a sequence of packagings, import
clauses, and class and object definitions, which may be preceded by a
package clause.
-A compilation unit
+A _compilation unit_
```scala
package $p_1$;
@@ -59,7 +59,7 @@ The exception to the implicit import of `scala.Predef` can be useful to hide, e.
Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’
```
-A package is a special object which defines a set of member classes,
+A _package_ is a special object which defines a set of member classes,
objects and packages. Unlike other objects, packages are not introduced
by a definition. Instead, the set of members of a package is determined by
packagings.
@@ -100,7 +100,7 @@ are visible to each other without qualification.
PackageObject ::= ‘package’ ‘object’ ObjectDef
```
-A package object `package object $p$ extends $t$` adds the
+A _package object_ `package object $p$ extends $t$` adds the
members of template $t$ to the package $p$. There can be only one
package object per package. The standard naming convention is to place
the definition above in a file named `package.scala` that's
diff --git a/spec/10-xml-expressions-and-patterns.md b/spec/10-xml-expressions-and-patterns.md
index b70fb86471..ea93cc8d8e 100644
--- a/spec/10-xml-expressions-and-patterns.md
+++ b/spec/10-xml-expressions-and-patterns.md
@@ -76,8 +76,8 @@ AttValue ::= ‘"’ {CharQ | CharRef} ‘"’
ScalaExpr ::= Block
-CharData ::= { CharNoRef } $\textit{ without}$ {CharNoRef}`{'CharB {CharNoRef}
- $\textit{ and without}$ {CharNoRef}`]]>'{CharNoRef}
+CharData ::= { CharNoRef } $\textit{ without}$ {CharNoRef}‘{’CharB {CharNoRef}
+ $\textit{ and without}$ {CharNoRef}‘]]>’{CharNoRef}
```
<!-- {% raw %} stupid liquid borks on the double brace below; brace yourself, liquid! -->
diff --git a/spec/11-annotations.md b/spec/11-annotations.md
index d66f24abf8..68faee53e6 100644
--- a/spec/11-annotations.md
+++ b/spec/11-annotations.md
@@ -56,7 +56,7 @@ Java platform, the following annotations have a standard meaning.
This is equivalent to a the following field
definition in Java:
- ```
+ ```java
private final static SerialVersionUID = <longlit>
```
@@ -94,7 +94,7 @@ Java platform, the following annotations have a standard meaning.
* `@deprecatedName(name: <symbollit>)`<br/>
Marks a formal parameter name as deprecated. Invocations of this entity
- using named parameter syntax refering to the deprecated parameter name cause a deprecation warning.
+ using named parameter syntax referring to the deprecated parameter name cause a deprecation warning.
### Scala Compiler Annotations
@@ -103,7 +103,7 @@ Java platform, the following annotations have a standard meaning.
matches which would otherwise be emitted. For instance, no warnings
would be produced for the method definition below.
- ```
+ ```scala
def f(x: Option[Int]) = (x: @unchecked) match {
case Some(y) => y
}
@@ -117,7 +117,7 @@ Java platform, the following annotations have a standard meaning.
value to appear in a path, even if its type is [volatile](03-types.html#volatile-types).
For instance, the following member definitions are legal:
- ```
+ ```scala
type A { type T }
type B
@uncheckedStable val x: A with B // volatile type
@@ -140,7 +140,7 @@ Java platform, the following annotations have a standard meaning.
For instance, the following code would generate specialized traits for
`Unit`, `Int` and `Double`
- ```
+ ```scala
trait Function0[@specialized(Unit, Int, Double) T] {
def apply: T
}
diff --git a/spec/12-the-scala-standard-library.md b/spec/12-the-scala-standard-library.md
index c3dc5cf196..e885dc7fb2 100644
--- a/spec/12-the-scala-standard-library.md
+++ b/spec/12-the-scala-standard-library.md
@@ -777,7 +777,7 @@ The available high-priority implicits include definitions falling into the follo
* An implicit wrapper that adds `ensuring` methods
with the following overloaded variants to type `Any`.
- ```
+ ```scala
def ensuring(cond: Boolean): A = { assert(cond); x }
def ensuring(cond: Boolean, msg: Any): A = { assert(cond, msg); x }
def ensuring(cond: A => Boolean): A = { assert(cond(x)); x }
@@ -787,7 +787,7 @@ The available high-priority implicits include definitions falling into the follo
* An implicit wrapper that adds a `->` method with the following implementation
to type `Any`.
- ```
+ ```scala
def -> [B](y: B): (A, B) = (x, y)
```
@@ -801,7 +801,7 @@ The available high-priority implicits include definitions falling into the follo
* An implicit wrapper that adds `+` and `formatted` method with the following
implementations to type `Any`.
- ```
+ ```scala
def +(other: String) = String.valueOf(self) + other
def formatted(fmtstr: String): String = fmtstr format self
```
@@ -835,7 +835,7 @@ The available high-priority implicits include definitions falling into the follo
* An implicit definition that generates instances of type `T <:< T`, for
any type `T`. Here, `<:<` is a class defined as follows.
- ```
+ ```scala
sealed abstract class <:<[-From, +To] extends (From => To)
```
diff --git a/spec/13-syntax-summary.md b/spec/13-syntax-summary.md
index 7f73e107de..be5cc1324e 100644
--- a/spec/13-syntax-summary.md
+++ b/spec/13-syntax-summary.md
@@ -11,7 +11,7 @@ The following descriptions of Scala tokens uses literal characters `‘c’` whe
_Unicode escapes_ are used to represent the Unicode character with the given hexadecimal code:
```ebnf
-UnicodeEscape ::= ‘\‘ ‘u‘ {‘u‘} hexDigit hexDigit hexDigit hexDigit
+UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ | … | ‘f’
```
@@ -30,7 +30,7 @@ delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
opchar ::= // printableChar not matched by (whiteSpace | upper | lower |
// letter | digit | paren | delim | opchar | Unicode_Sm | Unicode_So)
printableChar ::= // all characters in [\u0020, \u007F] inclusive
-charEscapeSeq ::= ‘\‘ (‘b‘ | ‘t‘ | ‘n‘ | ‘f‘ | ‘r‘ | ‘"‘ | ‘'‘ | ‘\‘)
+charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’)
op ::= opchar {opchar}
varid ::= lower idrest
@@ -38,7 +38,7 @@ plainid ::= upper idrest
| varid
| op
id ::= plainid
- | ‘`’ stringLiteral ‘`’
+ | ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’
idrest ::= {letter | digit} [‘_’ op]
integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
@@ -57,11 +57,12 @@ floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
booleanLiteral ::= ‘true’ | ‘false’
-characterLiteral ::= ‘'’ (printableChar | charEscapeSeq) ‘'’
+characterLiteral ::= ‘'’ (charNoQuoteOrNewline | UnicodeEscape | charEscapeSeq) ‘'’
stringLiteral ::= ‘"’ {stringElement} ‘"’
| ‘"""’ multiLineChars ‘"""’
-stringElement ::= (printableChar except ‘"’)
+stringElement ::= charNoDoubleQuoteOrNewline
+ | UnicodeEscape
| charEscapeSeq
multiLineChars ::= {[‘"’] [‘"’] charNoDoubleQuote} {‘"’}
@@ -128,18 +129,18 @@ grammar:
Expr ::= (Bindings | [‘implicit’] id | ‘_’) ‘=>’ Expr
| Expr1
- Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] `else' Expr]
- | `while' `(' Expr `)' {nl} Expr
- | `try' (`{' Block `}' | Expr) [`catch' `{' CaseClauses `}'] [`finally' Expr]
- | `do' Expr [semi] `while' `(' Expr ')'
- | `for' (`(' Enumerators `)' | `{' Enumerators `}') {nl} [`yield'] Expr
- | `throw' Expr
- | `return' [Expr]
- | [SimpleExpr `.'] id `=' Expr
- | SimpleExpr1 ArgumentExprs `=' Expr
+ Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr]
+ | ‘while’ ‘(’ Expr ‘)’ {nl} Expr
+ | ‘try’ (‘{’ Block ‘}’ | Expr) [‘catch’ ‘{’ CaseClauses ‘}’] [‘finally’ Expr]
+ | ‘do’ Expr [semi] ‘while’ ‘(’ Expr ‘)’
+ | ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr
+ | ‘throw’ Expr
+ | ‘return’ [Expr]
+ | [SimpleExpr ‘.’] id ‘=’ Expr
+ | SimpleExpr1 ArgumentExprs ‘=’ Expr
| PostfixExpr
| PostfixExpr Ascription
- | PostfixExpr `match' `{' CaseClauses `}'
+ | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’
PostfixExpr ::= InfixExpr [id [nl]]
InfixExpr ::= PrefixExpr
| InfixExpr id [nl] InfixExpr
@@ -189,12 +190,12 @@ grammar:
| varid
| Literal
| StableId
- | StableId ‘(’ [Patterns ‘)’
+ | StableId ‘(’ [Patterns] ‘)’
| StableId ‘(’ [Patterns ‘,’] [varid ‘@’] ‘_’ ‘*’ ‘)’
| ‘(’ [Patterns] ‘)’
| XmlPattern
Patterns ::= Pattern [‘,’ Patterns]
- | ‘_’ *
+ | ‘_’ ‘*’
TypeParamClause ::= ‘[’ VariantTypeParam {‘,’ VariantTypeParam} ‘]’
FunTypeParamClause::= ‘[’ TypeParam {‘,’ TypeParam} ‘]’
@@ -212,7 +213,7 @@ grammar:
[[nl] ‘(’ ‘implicit’ ClassParams ‘)’]
ClassParamClause ::= [nl] ‘(’ [ClassParams] ‘)’
ClassParams ::= ClassParam {‘,’ ClassParam}
- ClassParam ::= {Annotation} {Modifier} [(`val' | `var')]
+ ClassParam ::= {Annotation} {Modifier} [(‘val’ | ‘var’)]
id ‘:’ ParamType [‘=’ Expr]
Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’
Binding ::= (id | ‘_’) [‘:’ Type]
diff --git a/spec/15-changelog.md b/spec/15-changelog.md
index 751a571ecc..c88408682b 100644
--- a/spec/15-changelog.md
+++ b/spec/15-changelog.md
@@ -441,7 +441,7 @@ In the example, `Twice` is an extractor object with two methods:
- The `unapply` method is used to decompose an even number; it is in a sense
the reverse of `apply`. `unapply` methods return option types:
- `Some(...)` for a match that suceeds, `None` for a match that fails.
+ `Some(...)` for a match that succeeds, `None` for a match that fails.
Pattern variables are returned as the elements of `Some`.
If there are several variables, they are grouped in a tuple.
@@ -532,7 +532,7 @@ In particular, one can now simulate package protected access as in Java writing
where would name the package containing `X`.
-#### Relaxation of Private Acess
+#### Relaxation of Private Access
[Private members of a class](05-classes-and-objects.html#private) can now be
referenced from the companion module of the class and vice versa.
diff --git a/spec/README.md b/spec/README.md
index 1a201fc97c..ad524dfdf3 100644
--- a/spec/README.md
+++ b/spec/README.md
@@ -8,11 +8,15 @@ Third, we'd like to support different output formats. An html page per chapter w
## Editing
-We use Jekyll 2 and [Redcarpet](https://github.com/vmg/redcarpet) to generate the html. Essentially, this is what github pages use.
+At the time of writing we are using Jekyll 3.3.0 and [Redcarpet 3.3.2](https://github.com/vmg/redcarpet) to generate the html.
+
+Check `Gemfile` for the current versions.
+
+We aim to track the configuration GitHub Pages use but at times differences will arise as GitHub Pages evolves.
## Building
-Travis CI builds the spec automatically on every commit to master and publishes to http://www.scala-lang.org/files/archive/spec/2.11/.
+Travis CI builds the spec automatically after every merged pull release and publishes to http://www.scala-lang.org/files/archive/spec/2.12/.
To preview locally, run `bundle exec jekyll serve -d build/spec/ -s spec/ -w --baseurl=""` (in the root of your checkout of scala/scala),
and open http://0.0.0.0:4000/. Jekyll will rebuild as you edit the markdown, but make sure to restart it when you change `_config.yml`.
@@ -36,5 +40,5 @@ and open http://0.0.0.0:4000/. Jekyll will rebuild as you edit the markdown, but
### Unicode Character replacements
-- The unicode left and right single quotation marks (‘ and ’) have been used in place of ` and ', where the quotation marks are intended to be paired. These can be typed on a mac using Option+] for a left quote and Option+Shift+] for the right quote.
-- Similarly for left and right double quotation marks (“ and ”) in place of ". These can be typed on a mac using Option+[ and Option+Shift+].
+- The unicode left and right single quotation marks (‘ and ’ (U+2018 and U+2019, respectively)) have been used in place of ` and ', where the quotation marks are intended to be paired. These can be typed on a mac using Option+] for a left quote and Option+Shift+] for the right quote.
+- Similarly for left and right double quotation marks (“ and ” (U+201C and U+201D, respectively)) in place of ". These can be typed on a mac using Option+[ and Option+Shift+].
diff --git a/spec/_config.yml b/spec/_config.yml
index 74ec602f8f..1a67f7de63 100644
--- a/spec/_config.yml
+++ b/spec/_config.yml
@@ -1,7 +1,7 @@
-baseurl: /files/archive/spec/2.11
+baseurl: /files/archive/spec/2.12
safe: true
lsi: false
-highlighter: null
+highlighter: false
markdown: redcarpet
encoding: utf-8
redcarpet:
diff --git a/spec/_layouts/default.yml b/spec/_layouts/default.yml
index 20ebf22725..aa79e5ddab 100644
--- a/spec/_layouts/default.yml
+++ b/spec/_layouts/default.yml
@@ -31,7 +31,7 @@
<body>
<header>
- <nav id="chapters"><a id="github" href="https://github.com/scala/scala/tree/2.11.x/spec"><img src="public/images/github-logo@2x.png" alt="Edit at Github"></a>{% assign sorted_pages = site.pages | sort:"name" %}{% for post in sorted_pages %}{% if post.chapter >= 0 %}<a href="{{site.baseurl}}{{ post.url }}">{{post.chapter}} {{ post.title }}</a>{% endif %}{% endfor %}</nav>
+ <nav id="chapters"><a id="github" href="https://github.com/scala/scala/tree/2.12.x/spec"><img src="public/images/github-logo@2x.png" alt="Edit at GitHub"></a>{% assign sorted_pages = site.pages | sort:"name" %}{% for post in sorted_pages %}{% if post.chapter >= 0 %}<a href="{{site.baseurl}}{{ post.url }}">{{post.chapter}} {{ post.title }}</a>{% endif %}{% endfor %}</nav>
</header>
<aside class="left"><nav id="toc"></nav></aside>
diff --git a/spec/_layouts/toc.yml b/spec/_layouts/toc.yml
index 4da7d41bea..dfd92eb114 100644
--- a/spec/_layouts/toc.yml
+++ b/spec/_layouts/toc.yml
@@ -19,9 +19,9 @@
<div id="header-main">
<img id="scala-logo" src="public/images/scala-spiral-white.png" />
<span id="title">Scala Language Specification</span>
- <a id="github" href="https://github.com/scala/scala/tree/2.11.x/spec"><img src="public/images/github-logo@2x.png" alt="Edit at Github"></a>
+ <a id="github" href="https://github.com/scala/scala/tree/2.12.x/spec"><img src="public/images/github-logo@2x.png" alt="Edit at GitHub"></a>
</div>
- <div id="header-sub">Version 2.11</div>
+ <div id="header-sub">Version 2.12</div>
</header>
<main>
{{ content }}
diff --git a/spec/id_dsa_travis.enc b/spec/id_dsa_travis.enc
index a9a4036807..16bbd569dc 100644
--- a/spec/id_dsa_travis.enc
+++ b/spec/id_dsa_travis.enc
@@ -1,15 +1,68 @@
-U2FsdGVkX1/RKhLZeL93vFQikKRRkoa3rqt6Kbs7cJStmcTI+DohoRUidRaeSULa
-+xXQCwaSDs4+l1HdW2R4ZV62AVGhvIeKEZxc449c6qT9+wUd2PKkDghuJCy1dLTo
-2OdFLDeop0X32bsauzPQGWwrpb/Llck4KeKffJq2257Hu6T/HnzSfDnvXbjAsVeH
-ZLeXURAyDAdK9vFmFzFiEEztLkW8E3ZVyrk7Qa3GPNpmATiBdhVM8d0JJptKVgwQ
-mZfhbItLrj490sPd5zpUFKAxJjPoKIa75n/+u4butn+ON97vr7xOy6ElX7HSJUgr
-FJdVJgcO7lki0j+lfJVAP0zLnH80CgOkOJSq0Sso/ofs+lQIobo8fQqIdmoqV3z2
-KpYrgnqap1U2+ekIUKsUxk4LuO8uJhwPeMJs6FoDb+O4Aauqpy9242+P05gWkQVd
-KVWRcHVE7DulS8Fp/o5GXJUdw+rdxvQ/voJ8i0HbYpp6UcmQwBheQMSmqtp5+ML9
-rBiBe2sr7pahqI5NKoF3iZCkZW74ge3/GP2d6m2tpOzD+IfdFDXQ/r8DbK2Dvwvz
-eutOb0zrUtua2e2zvvpVxldPVpXA7A1hE0P3lns9o+TqNhEauTQimQ8/X51BHO6E
-Ap4odrf2odocacY5VC4LFYDO3vat0wSTpi6SxkemUMX5yB7euqwD3ZrMcbpPFR1B
-IU5XxW20NxUo8n+WuMUNkXTgk/Cr4OUiavVv4oLsHkmgD9LN3IYI6Rj/DSCzSbDx
-hyWc7R47iu9f5okQScx62DwVK3AyAuVWer94x0Kj8AcIRwU/VwiXjnZ59I89AKTN
-sjZJw1FfpJPqYs7fPtEiotUdaJHzJH8tiEWFrtOTuOg3h6fy0KJTPVh0WjcGXfb6
-Uh1SEgeHtMSUVhq8nd8LGQ==
+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