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 address the comments in this review: #672 (review)
except for any grammar changes.
Notes on where the edit differs (slightly) from the recommendation:
- The rule that a `using` statement can't declare an `out` variable applies to all forms. I added that in 13.14.1.
- I added a note that ref structs can't use the form of `await using`. It's a note because it follows from the normative restriction that `ref struct` types can't implement interfaces, but `await using` requires the resource type to implement `IAsyncDisposable`.
- The rules for `goto`, `break`, etc. are a note at the end of 13.14.1. They can be derived from the expanded forms of the `using` statement.
- The rule for a using declaration in a switch block remains. It's specific to a using declaration.
When *local_variable_declaration* includes `using`, thesemanticsdescribedabovearemodified, asfollows.
355
-
356
-
Each*local_variable_type*shallbe `dynamic` oraresourcetype. If `await` isalsopresent, theresourcetypeshallnotbearef struct.
357
-
358
-
Each *local_variable_declarator* shall have a *local_variable_initializer*.
359
-
360
-
The variables declared are read-only. A compile-time error occurs if any subsequent statement attempts to modify these variables, take the address of them, or pass them as reference or output parameters.
361
-
362
-
An occurrence of *local_variable_declaration* containing `using` has the same semantics as, and can be rewritten as, the corresponding resource-acquisition form of the using statement ([§13.14](statements.md#1314-the-using-statement)), as follows:
363
-
364
-
```csharp
365
-
using «local_variable_type» «local_variable_declarators»
366
-
// statements
367
-
```
368
-
369
-
is equivalent to
370
-
371
-
```csharp
372
-
using («local_variable_type» «local_variable_declarators»)
When jumping to a label in a statement list which contains *local_variable_declaration*s involving `using`, there must not be any such declaration between the `goto` statement and the label.```
410
-
411
-
Apart from wordsmithing this needs x-ref to goto, and goto probably needs this restriction listed in its description as well.
412
-
413
-
Also surely this is an echo of a similar statement for `using (…) {…}`, so is it needed here at all given the equivalency defined above – this is just a shorthand.
414
-
415
-
A *local_variable_declaration* with `using` shall not appear directly inside a `case` label, but, instead, may be within a block inside a `case` label.
416
-
417
-
A *local_variable_declaration* with `using` shall not appear in an `out` variable declaration.
418
-
419
354
#### 13.6.2.2 Implicitly typed local variable declarations
420
355
421
356
```ANTLR
@@ -1941,6 +1876,8 @@ While a mutual-exclusion lock is held, code executing in the same execution thre
1941
1876
1942
1877
## 13.14 The using statement
1943
1878
1879
+
### §using_general General
1880
+
1944
1881
The `using` statementobtainsoneormoreresources, executesastatement, andthendisposesoftheresource.
1945
1882
1946
1883
```ANTLR
@@ -1956,7 +1893,9 @@ resource_acquisition
1956
1893
1957
1894
A***resource***iseitheraclassornon-refstructthatimplementseitherorbothofthe `System.IDisposable` or `System.`IAsync`Disposable` interfaces, whichincludesasingleparameterlessmethodnamed `Dispose` and/or `DisposeAsync`; orarefstructthatincludesamethodnamed `Dispose` havingthesamesignatureasthatdeclaredby `System.IDisposable`. Codethatisusingaresourcecancall `Dispose` or `DisposeAsync` toindicatethattheresourceisnolongerneeded.
1958
1895
1959
-
Iftheformof *resource_acquisition* is *local_variable_declaration* thenthetypeofthe *local_variable_declaration* shallbeeither `dynamic` oraresourcetype. Iftheformof *resource_acquisition* is *expression* thenthisexpressionshallhavearesourcetype. If `await` ispresent, theresourcetypeshallimplement `System.IAsyncDisposable`.
1896
+
Iftheformof *resource_acquisition* is *local_variable_declaration* thenthetypeofthe *local_variable_declaration* shallbeeither `dynamic` oraresourcetype. The *local_variable_declaration* cannotincludethe `out` modifier. Iftheformof *resource_acquisition* is *expression* thenthisexpressionshallhavearesourcetype. If `await` ispresent, theresourcetypeshallimplement `System.IAsyncDisposable`.
Localvariablesdeclaredina*resource_acquisition*areread-only, andshallincludeaninitializer. Acompile-timeerroroccursiftheembeddedstatementattemptstomodifytheselocalvariables (viaassignmentorthe `++` and `--` operators), taketheaddressofthem, orpassthemasreferenceoroutputparameters.
1962
1901
@@ -2133,6 +2072,59 @@ corresponds to
2133
2072
2134
2073
When `ResourceType` is a reference type that implements `IAsyncDisposable`. Other expansions for `await using` perform similar substitutions from the synchronous `Dispose` method to the asynchronous `DisposeAsync` method.
2135
2074
2075
+
> *Note*: Any jump statements (§13.10) in the *embedded_statement* must conform to expanded form of the `using` statement. *end note*
2076
+
2077
+
### §using_declarations Using declarations
2078
+
2079
+
A syntactic variant of the using statement is a *using declaration*. A *using declaration* has the same semantics as, and can be rewritten as, the corresponding resource-acquisition form of the using statement (§using_general), as follows:
2080
+
2081
+
```csharp
2082
+
using «local_variable_type» «local_variable_declarators»
2083
+
// statements
2084
+
```
2085
+
2086
+
isequivalentto
2087
+
2088
+
```csharp
2089
+
using («local_variable_type» «local_variable_declarators»)
A using declaration shall not appear directly inside a `case` label, but, instead, may be within a block inside a `case` label.
2127
+
2136
2128
## 13.15 The yield statement
2137
2129
2138
2130
The `yield` statement is used in an iterator block ([§13.3](statements.md#133-blocks)) to yield a value to the enumerator object ([§15.15.5](classes.md#15155-enumerator-objects)) or enumerable object ([§15.15.6](classes.md#15156-enumerable-objects)) of an iterator or to signal the end of the iteration.
0 commit comments