Skip to content

Case where old extensions cannot be converted to new extensions due to overloading by ref #79043

@hamarb123

Description

@hamarb123

Version Used: .NET Lab & Godbolt

Steps to Reproduce:

Old version:

public static class A
{
    public static void M<T>(this T value) where T : class { }
    public static void M<T>(this ref T value) where T : struct { }
}

New version:

public static class B
{
    extension<T>(T inst) where T : class
    {
        public void M() { }
    }
    extension<T>(ref T inst) where T : struct
    {
        public void M() { }
    }
}

Godbolt

.NET Lab

Diagnostic Id:
error CS0111: Type 'B' already defines a member called 'M' with the same parameter types

Expected Behavior:
Compiles since they get lowered to methods that don't conflict in IL, and it worked previously.

Actual Behavior:
Does not compile, so cannot convert into the new extension style.

Relates to test plan #76130

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions