-
Notifications
You must be signed in to change notification settings - Fork 93
Description
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.
class C {
int field;
ref int ShortProperty => ref field;
ref int LongProperty { get => ref field; }
ref int this[int index] => ref field;
ref int Method() => ref field;
void Outer() {
ref int Inner() => ref field;
}
}
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 of return
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 what ref
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 allow ref
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)