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.
|
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,
|
declaration_statement |
|
: local_variable_declaration ';' |
|
| local_constant_declaration ';' |
|
| local_function_declaration |
|
; |
The Roslyn compiler parser performs the test in ParseStatementStartingWithUsing():
https://github.com/dotnet/roslyn/blob/f881263cdd42dc2526afe797d678c644414f7b3f/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs#L8475-L8476
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
v8test-embedded-statement.zip
Describe the bug
Consider this example:
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
And, more critically,
csharpstandard/standard/statements.md
Lines 284 to 288 in 089fae9
The Roslyn compiler parser performs the test in ParseStatementStartingWithUsing():
https://github.com/dotnet/roslyn/blob/f881263cdd42dc2526afe797d678c644414f7b3f/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs#L8475-L8476
The most natural location for "| using_declaration" would be in "declaration_statement".
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
v8test-embedded-statement.zip