-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# 7.3 method_body etc. grammar does not allow => ref
#825
Comments
=> ref
=> ref
@Nigel-Ecma: If you've got bandwidth to look at this, that would be great - if not, let me know and I'll see if @gafter can. |
The specification of this feature should be at https://github.com/dotnet/csharplang/blob/cd336064a26a43c31c1164ef7cd3f5feb4420d20/proposals/csharp-7.0/expression-bodied-everything.md or https://github.com/dotnet/csharplang/blob/cd336064a26a43c31c1164ef7cd3f5feb4420d20/proposals/csharp-7.0/ref-locals-returns.md but both are only placeholders. |
Covered by PR #837 |
(This was originally in dotnet#837.) The grammar has been extended to be as prescriptive as reasonably possible as befits a language specification[1], this means that former statements such as it being illegal to have a set accessor for a ref-valued property are now covered by the grammar. However the usual verbose description of the grammar remains! The term ref-valued rather than ref-returning is used, a term closer to the language of fields. To distingush the two kinds of properties, which do follow different rules, the corresponding and somewhat ugly term non-ref-valued is used (non-ref-returning would be just as ugly). [1] The grammar used by a compiler may be less restrictive to support more descriptive error messages, that is of course an implementation issue! Fixes dotnet#825.
(This was originally in #837.) The grammar has been extended to be as prescriptive as reasonably possible as befits a language specification[1], this means that former statements such as it being illegal to have a set accessor for a ref-valued property are now covered by the grammar. However the usual verbose description of the grammar remains! The term ref-valued rather than ref-returning is used, a term closer to the language of fields. To distingush the two kinds of properties, which do follow different rules, the corresponding and somewhat ugly term non-ref-valued is used (non-ref-returning would be just as ugly). [1] The grammar used by a compiler may be less restrictive to support more descriptive error messages, that is of course an implementation issue! Fixes #825.
Describe the bug
In C# 7.3, a method/property/accessor/indexer body
=> ref variable_reference;
should be allowed and mean the same as{ return ref variable_reference; }
. Roslyn allows this, but the grammar in the C# 7 draft doesn't.This issue concerns multiple clauses, listed under "Expected behavior" below.
Example
The following should be allowed, but
=> ref field
does not match the syntactic grammar.Expected behavior
In §15.7.1 (Classes / Properties / General), property_body should allow
=>
ref
variable_reference;
.In §15.7.3 (Classes / Properties / Accessors), accessor_body should allow
=>
ref
variable_reference;
.In §15.9 (Classes / Indexers), indexer_body should allow
=>
ref
variable_reference;
.In §15.6.1 (Classes / Methods / General), method_body should allow
=>
ref
variable_reference;
.In §13.6.4 (Statements / Declaration statements / Local function declarations), local_function_body should allow
=>
ref
variable_reference;
.The standard should specify what the
=>
ref
syntax means, perhaps by reference to §13.10.5 (Statements / Jump statements / The return statement), which specifies the meaning ofreturn
ref
.Additional context
In §12.19.1 (Expressions / Anonymous function expressions / General), anonymous_function_body already allows
ref
variable_reference. However, I haven't found anything that specifies whatref
means in this context.In §15.10.1 (Classes / Operators / General), operator_body does not allow
=>
ref
variable_reference;
but this is OK as operators cannot return by reference; operator_declarator does not allowref
either.In §15.11.1 (Classes / Instance constructors / General), constructor_body does not allow
=>
ref
variable_reference;
but this is OK as instance constructors cannot return values either.In §15.12 (Classes / Static constructors), static_constructor_body does not allow
=>
ref
variable_reference;
but this is OK as static constructors cannot return values either.In §15.13 (Classes / Finalizers), finalizer_body does not allow
=>
ref
variable_reference;
but this is OK as finalizers cannot return values either.Elaborated from #213 (comment)
The text was updated successfully, but these errors were encountered: