Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small tweaks to "Local variable declarations" #1208

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
- [§13.6.2.1](statements.md#13621-general) General
- [§13.6.2.2](statements.md#13622-implicitly-typed-local-variable-declarations) Implicitly typed local variable declarations
- [§13.6.2.3](statements.md#13623-explicitly-typed-local-variable-declarations) Explicitly typed local variable declarations
- [§13.6.2.4](statements.md#13624-ref-local-variable-declarations) Ref local variable declarations
- [§13.6.2.4](statements.md#13624-explicitly-typed-ref-local-variable-declarations) Explicitly typed ref local variable declarations
- [§13.6.3](statements.md#1363-local-constant-declarations) Local constant declarations
- [§13.6.4](statements.md#1364-local-function-declarations) Local function declarations
- [§13.7](statements.md#137-expression-statements) Expression statements
Expand Down
10 changes: 4 additions & 6 deletions standard/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,10 @@ A *local_variable_declaration* declares one or more local variables.
local_variable_declaration
: implicitly_typed_local_variable_declaration
| explicitly_typed_local_variable_declaration
| ref_local_variable_declaration
| explicitly_typed_ref_local_variable_declaration
;
```

Local variable declarations fall into one of the three categories: implicitly typed, explicitly typed, and ref local.

Implicitly typed declarations contain the contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)) `var` resulting in a syntactic ambiguity between the three categories which is resolved as follows:

- If there is no type named `var` in scope and the input matches *implicitly_typed_local_variable_declaration* then it is chosen;
Expand Down Expand Up @@ -366,7 +364,7 @@ implicitly_typed_local_variable_declarator
;
```

An *implicity_typed_local_variable_declaration* introduces a single local variable, *identifier*. The *expression* or *variable_reference* shall have a compile-time type, `T`. The first alternative declares a variable with an initial value of *expression*; its type is `T?` when `T` is a non-nullable reference type, otherwise its type is `T`. The second alternative declares a ref variable with an initial value of `ref` *variable_reference*; its type is `ref T?` when `T` is a non-nullable reference type, otherwise its type is `ref T`.
An *implicity_typed_local_variable_declaration* introduces a single local variable, *identifier*. The *expression* or *variable_reference* shall have a compile-time type, `T`. The first alternative declares a variable with an initial value of *expression*; its type is `T?` when `T` is a non-nullable reference type, otherwise its type is `T`. The second alternative declares a ref variable with an initial value of `ref` *variable_reference*; its type is `ref T?` when `T` is a non-nullable reference type, otherwise its type is `ref T`. (`ref_kind` is described in [§15.6.1](classes.md#1561-general).)

> *Example*:
>
Expand Down Expand Up @@ -433,10 +431,10 @@ An *explicity_typed_local_variable_declaration* introduces one or more local var

If a *local_variable_initializer* is present then its type shall be appropriate according to the rules of simple assignment ([§12.21.2](expressions.md#12212-simple-assignment)) or array initialization ([§17.7](arrays.md#177-array-initializers)) and its value is assigned as the initial value of the variable.

#### 13.6.2.4 Ref local variable declarations
#### 13.6.2.4 Explicitly typed ref local variable declarations

```ANTLR
ref_local_variable_declaration
explicitly_typed_ref_local_variable_declaration
: ref_kind type ref_local_variable_declarators
;

Expand Down
Loading