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

No error reported for overload ambiguity with extension methods with identical signatures and params arrays #72696

Closed
cston opened this issue Mar 23, 2024 · 2 comments · Fixed by #72706
Assignees
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@cston
Copy link
Member

cston commented Mar 23, 2024

Version Used:

main: 7ecf61f

Steps to Reproduce:

Compile the following:

using System.Collections;
using System.Collections.Generic;

class MyCollection<T> : IEnumerable<T>
{
    IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw null;
    IEnumerator IEnumerable.GetEnumerator() => throw null;
}

static class ExtensionsA
{
    public static void Add<T>(this MyCollection<T> collection, params string[] args) { }
}

static class ExtensionsB
{
    public static void Add<T>(this MyCollection<T> collection, params string[] args) { }
}

class Program
{
    static void Main()
    {
        var x = new MyCollection<object>();
        x.Add("");
        
        var y = new MyCollection<object> { "" };
    }
}

Expected Behavior:

The following errors are expected, as reported by 4.10.0-3.24161.9 (b0be498).

(25,11): error CS0121: The call is ambiguous between the following methods or properties:
    'ExtensionsA.Add<T>(MyCollection<T>, params string[])' and
    'ExtensionsB.Add<T>(MyCollection<T>, params string[])'
(27,44): error CS0121: The call is ambiguous between the following methods or properties:
    'ExtensionsA.Add<T>(MyCollection<T>, params string[])' and
    'ExtensionsB.Add<T>(MyCollection<T>, params string[])'

Actual Behavior:

No errors.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 23, 2024
@cston
Copy link
Member Author

cston commented Mar 23, 2024

cc @AlekseyTs

@AlekseyTs
Copy link
Contributor

It looks like IsBetterCollectionExpressionConversion is not designed to be called with identical type, which happens for params scenario from IsBetterParamsCollectionType.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants