Skip to content

Commit 8f893c5

Browse files
committed
Update grammar
Update grammar based on #672 (review)
1 parent 0994740 commit 8f893c5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

standard/statements.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,14 +1886,19 @@ using_statement
18861886
;
18871887
18881888
resource_acquisition
1889-
: local_variable_declaration
1889+
: non_ref_local_variable_declaration
18901890
| expression
18911891
;
1892+
1893+
non_ref_local_variable_declaration
1894+
: implicitly_typed_local_variable_declaration
1895+
| explicitly_typed_local_variable_declaration
1896+
;
18921897
```
18931898
18941899
A ***resource*** is either a class or non-ref struct that implements either or both of the `System.IDisposable` or `System.`IAsync`Disposable` interfaces, which includes a single parameterless method named `Dispose` and/or `DisposeAsync`; or a ref struct that includes a method named `Dispose` having the same signature as that declared by `System.IDisposable`. Code that is using a resource can call `Dispose` or `DisposeAsync` to indicate that the resource is no longer needed.
18951900
1896-
If the form of *resource_acquisition* is *local_variable_declaration* then the type of the *local_variable_declaration* shall be either `dynamic` or a resource type. The *local_variable_declaration* cannot include the `out` modifier. If the form of *resource_acquisition* is *expression* then this expression shall have a resource type. If `await` is present, the resource type shall implement `System.IAsyncDisposable`.
1901+
If the form of *resource_acquisition* is *local_variable_declaration* then the type of the *local_variable_declaration* shall be either `dynamic` or a resource type. If the form of *resource_acquisition* is *expression* then this expression shall have a resource type. If `await` is present, the resource type shall implement `System.IAsyncDisposable`.
18971902
18981903
> *Note:* A `ref struct` type cannot be the resource type for a `using` statement with the `await` modifier because `ref struct` types cannot implement interfaces. *end note*
18991904
@@ -2074,9 +2079,17 @@ When `ResourceType` is a reference type that implements `IAsyncDisposable`. Othe
20742079

20752080
> *Note*: Any jump statements (§13.10) in the *embedded_statement* must conform to expanded form of the `using` statement. *end note*
20762081
2077-
### §using_declarations Using declarations
2082+
### §using_declarations Using declaration
2083+
2084+
A syntactic variant of the using statement is a *using declaration*.
2085+
2086+
```ANTLR
2087+
using_declaration
2088+
: await? 'using' non_ref_local_variable_declaration ';' statement_list?
2089+
;
2090+
```
20782091

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:
2092+
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:
20802093

20812094
```csharp
20822095
using «local_variable_type» «local_variable_declarators»

0 commit comments

Comments
 (0)