Skip to content
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 interface_method_declaration etc. grammar does not allow return by reference #826

Closed
KalleOlaviNiemitalo opened this issue Jun 28, 2023 · 2 comments
Labels
type: bug The Standard does not describe the language as intended or implemented
Milestone

Comments

@KalleOlaviNiemitalo
Copy link
Contributor

KalleOlaviNiemitalo commented Jun 28, 2023

Describe the bug
In C# 7.3, a method, property, or indexer as a member of an interface should be able to return by (readonly) reference, but the syntactic grammar does not allow this.

§18.4.2, §18.4.3, §18.4.5.

Example

The following should be allowed, but ref does not match the syntactic grammar.

interface I {
    ref int Method();
    ref int Property { get; }
    ref int this[int index] { get; }
}

Expected behavior

In §18.4.2, interface_method_declaration should allow ref or ref readonly before return_type.

In §18.4.3, interface_property_declaration should allow ref or ref readonly before type. It is not necessary to explicitly forbid a set accessor on such a property, because the text already references §15.7.3, which states: "A ref-returning property shall not have a set accessor."

In §18.4.5, interface_indexer_declaration should allow ref or ref readonly before type. It is not necessary to explicitly forbid a set accessor on such an indexer, because the text already references §15.9, which states: "Aside from these differences, all rules defined in §15.7.3 and §15.7.4 apply to indexer accessors as well as to property accessors."

Additional context

In §18.4.4, interface_event_declaration does not allow ref, but that is OK, because the type is not the return type of any accessor of the event.

Operators cannot be members of interfaces, and they do not allow ref in classes and structs either.

@jskeet jskeet added this to the C# 7.x milestone Jul 4, 2023
@jskeet jskeet added the type: bug The Standard does not describe the language as intended or implemented label Jul 4, 2023
@jskeet
Copy link
Contributor

jskeet commented Jul 4, 2023

@Nigel-Ecma: With your grammarian hat on, does this look like it's easy enough to fix?

@Nigel-Ecma
Copy link
Contributor

This will be covered by PR #837 along with issue #825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The Standard does not describe the language as intended or implemented
Projects
None yet
Development

No branches or pull requests

3 participants