-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Describe the bug
Consider this example:
using System.IO;
class Program
{
static void Main()
{
using var r = new StringReader("hello");
}
}
This code compiles and runs perfectly fine with version 8 of the Roslyn compiler. (It does not for version 7.)
This input does not parse using the scraped grammar, using the latest on "draft-v8" branch. This is because there is an error with the statement rules.
csharpstandard/standard/statements.md
Lines 10 to 31 in 089fae9
| statement | |
| : labeled_statement | |
| | declaration_statement | |
| | embedded_statement | |
| ; | |
| embedded_statement | |
| : block | |
| | empty_statement | |
| | expression_statement | |
| | selection_statement | |
| | iteration_statement | |
| | jump_statement | |
| | try_statement | |
| | checked_statement | |
| | unchecked_statement | |
| | lock_statement | |
| | using_statement | |
| | yield_statement | |
| | unsafe_statement // unsafe code support | |
| | fixed_statement // unsafe code support | |
| ; |
And, more critically,
csharpstandard/standard/statements.md
Lines 284 to 288 in 089fae9
| declaration_statement | |
| : local_variable_declaration ';' | |
| | local_constant_declaration ';' | |
| | local_function_declaration | |
| ; |
The Roslyn compiler parser performs the test in ParseStatementStartingWithUsing():
The most natural location for "| using_declaration" would be in "declaration_statement".
declaration_statement
: local_variable_declaration ';'
| local_constant_declaration ';'
| local_function_declaration
| using_declaration
;
You'll need to decide what may be more natural point in the EBNF to make a change, perhaps local_variable_declaration but that would require a bit more refactoring.
In any case, the grammar as is does not work.
Example