Skip to content

C# 7.3 interface_method_declaration etc. grammar does not allow return by reference #826

@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugThe Standard does not describe the language as intended or implemented

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions