You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit embeds the reworked §13.6.2 into the rest of the text by dealing with thge linkages between them.
In particular:
- The term *declarator* has been turned into the defined term ***declarator*** thus allowing other clauses which used to refer to *local_variable_declarator* to use it instead and simplify language at the same time.
- The wording of the scope of a `for` variable has been made consisent between Statements & Basic Concepts – just word smithing using a blending of the two, no change in semantics.
- The production *local_variable_type* has been moved from `foreach` to the textually earlier declaration expression, just seems more logical.
I'll now remove the "draft" status of the PR, go at it folks!
<!-- The following restrictions apply to C# 7.3, they are relaxed in C# 8 -->
3149
3149
A *stackalloc_expression* is only permitted in two contexts:
3150
3150
3151
-
1. The *expression*, `E`, of a *local_variable_initializer* of a *local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)); and
3151
+
1. The initializing *expression*, `E`, of a *local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)); and
3152
3152
2. The right operand *expression*, `E`, of a simple assignment ([$12.21.2](expressions.md#12212-simple-assignment)) which itself occurs as a *expression_statement* ([§13.7](statements.md#137-expression-statements))
3153
3153
3154
3154
In both contexts the *stackalloc_expression* is only permitted to occur as:
@@ -4712,6 +4712,11 @@ A declaration expression declares a local variable.
4712
4712
declaration_expression
4713
4713
: local_variable_type identifier
4714
4714
;
4715
+
4716
+
local_variable_type
4717
+
: type
4718
+
| 'var'
4719
+
;
4715
4720
```
4716
4721
4717
4722
The *simple_name*`_` is also considered a declaration expression if simple name lookup did not find an associated declaration ([§12.8.4](expressions.md#1284-simple-names)). When used as a declaration expression, `_` is called a *simple discard*. It is semantically equivalent to `var _`, but is permitted in more places.
- If there is no type named `var` in scope and the input matches *implicitly_typed_local_variable_declaration* then it is chosen;
312
312
- Otherwise if a type named `var` is in scope then *implicitly_typed_local_variable_declaration* is not considered as a possible match.
313
313
314
-
Within a *local_variable_declaration* each variable is introduced by a *declarator*, which is one of *implicitly_typed_local_variable_declarator*, *explicitly_typed_local_variable_declarator* or *ref_local_variable_declarator* for impicitly typed, explicitly typed and ref local variables respectively. The declarator defines the name (*identifier*) and initial value, if any, of the introduced variable.
314
+
Within a *local_variable_declaration* each variable is introduced by a ***declarator***, which is one of *implicitly_typed_local_variable_declarator*, *explicitly_typed_local_variable_declarator* or *ref_local_variable_declarator* for impicitly typed, explicitly typed and ref local variables respectively. The declarator defines the name (*identifier*) and initial value, if any, of the introduced variable.
315
315
316
316
If there are multiple declarators in a declaration then they are processed, including any initializing expressions, in order left to right ([§9.4.4.5](variables.md#9445-declaration-statements)).
317
317
@@ -343,7 +343,7 @@ The value of a local variable is obtained in an expression using a *simple_name*
The *for_initializer*, if present, consists of either a *local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)) or a list of *statement_expression*s ([§13.7](statements.md#137-expression-statements)) separated by commas. The scope of a local variable declared by a *for_initializer*starts at the *local_variable_declarator* for the variable and extends to the end of the embedded statement. The scope includes the *for_condition*and the *for_iterator*.
1066
+
The *for_initializer*, if present, consists of either a *local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)) or a list of *statement_expression*s ([§13.7](statements.md#137-expression-statements)) separated by commas. The scope of a local variable declared by a *for_initializer*is the *for_initializer*, *for_condition*, *for_iterator*, and *embedded_statement*.
1067
1067
1068
1068
The *for_condition*, if present, shall be a *boolean_expression* ([§12.24](expressions.md#1224-boolean-expressions)).
The *local_variable_type* and *identifier* of a foreach statement declare the ***iteration variable*** of the statement. If the `var` identifier is given as the *local_variable_type*, and no type named `var` is in scope, the iteration variable is said to be an ***implicitly typed iteration variable***, and its type is taken to be the element type of the `foreach` statement, as specified below.
Copy file name to clipboardExpand all lines: standard/unsafe-code.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1049,7 +1049,7 @@ When the outermost containing struct variable of a fixed-size buffer member is a
1049
1049
1050
1050
See [§12.8.21](expressions.md#12821-stack-allocation) for general information about the operator `stackalloc`. Here, the ability of that operator to result in a pointer is discussed.
1051
1051
1052
-
In an unsafe context if a *stackalloc_expression* ([§12.8.21](expressions.md#12821-stack-allocation)) occursasthe*local_variable_initializer*ofa*local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)), wherethe*local_variable_type*iseitherapointertype ([§23.3](unsafe-code.md#233-pointer-types)) orinferred (`var`), thentheresultofthe*stackalloc_expression*isapointeroftype `T *` tobebeginningoftheallocatedblock, where `T` isthe *unmanaged_type* ofthe *stackalloc_expression*.
1052
+
In an unsafe context if a *stackalloc_expression* ([§12.8.21](expressions.md#12821-stack-allocation)) occursastheinitializingexpressionofa*local_variable_declaration* ([§13.6.2](statements.md#1362-local-variable-declarations)), wherethe*local_variable_type*iseitherapointertype ([§23.3](unsafe-code.md#233-pointer-types)) orinferred (`var`), thentheresultofthe*stackalloc_expression*isapointeroftype `T *` tobebeginningoftheallocatedblock, where `T` isthe *unmanaged_type* ofthe *stackalloc_expression*.
Copy file name to clipboardExpand all lines: standard/variables.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,7 +124,7 @@ A ***local variable*** is declared by a *local_variable_declaration*, *declarati
124
124
125
125
A *local_variable_declaration* canoccurina *block*, a *for_statement*, a *switch_block*, ora *using_statement*. A *declaration_expression* canoccurasan `out` *argument_value*, andasa *tuple_element* thatisthetargetofadeconstructingassignment ([§12.21.2](expressions.md#12212-simple-assignment)).
0 commit comments