Skip to content

Confusing error message when using in this with an enum #73746

@JakeYallop

Description

@JakeYallop

There is a confusing error message when using in this with an enum. For example, the below

sharplab

public static class Ext
{
    public static void M1(in this int i) { } //no error
    public static void M2(this in MyEnum kind) { } //error!
}

public enum MyEnum : int
{
    One
}

Produces

error CS8338: The first 'in' or 'ref readonly' parameter of the extension method 'M2' must be a concrete (non-generic) value type.

for M2.

Its unclear to me exactly what the expected behaviour should be here - but if all types that are valid for enums are struct types, and if in this int is allowed, then it follows that in this <some enum> should also be allowed.

If MyEnum is not allowed, it would be good to improve the error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compilershelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions