Skip to content

Commit

Permalink
Small tweaks to "Local variable declarations" (#1208)
Browse files Browse the repository at this point in the history
* improved text and rule names

* change section heading

* fix grammar edit error

* Update standard/statements.md

Co-authored-by: Nigel-Ecma <[email protected]>

* Update standard/statements.md

Co-authored-by: Nigel-Ecma <[email protected]>

* Update standard/statements.md

Co-authored-by: Kalle Olavi Niemitalo <[email protected]>

---------

Co-authored-by: Nigel-Ecma <[email protected]>
Co-authored-by: Kalle Olavi Niemitalo <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2024
1 parent 5d74d23 commit 000309e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
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 *implicitly_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

0 comments on commit 000309e

Please sign in to comment.