Skip to content

Commit 77a9910

Browse files
committed
Spec: uninitialized instead of wildcard init.
1 parent f9f7f56 commit 77a9910

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ A variable definition `var ´p´ = ´e´` where ´p´ is a pattern other than a
163163

164164
The name of any declared or defined variable may not end in `_=`.
165165

166-
A variable definition `var ´x´: ´T´ = _` can appear only as a member of a template.
166+
The right-hand-side of a mutable variable definition that is a member of a template can be the special reference `scala.compiletime.uninitialized`: `var ´x´: ´T´ = scala.compiletime.uninitialized`.
167167
It introduces a mutable field with type ´T´ and a default initial value.
168168
The default value depends on the type ´T´ as follows:
169169

@@ -177,6 +177,9 @@ The default value depends on the type ´T´ as follows:
177177
|`()` | `Unit` |
178178
|`null` | all other types |
179179

180+
`scala.compiletime.uninitialized` can never appear anywhere else.
181+
For compatibility with Scala 2, the syntax `var ´x´: ´T´ = _` is accepted as equivalent to using `uninitialized`.
182+
180183
When they occur as members of a template, both forms of variable definition also introduce a getter method ´x´ which returns the value currently assigned to the variable, as well as a setter method `´x´_=` which changes the value currently assigned to the variable.
181184
The methods have the same signatures as for a variable declaration.
182185
The template then has these getter and setter methods as members, whereas the original variable cannot be accessed directly as a template member.

0 commit comments

Comments
 (0)