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

"The call is ambiguous" error when using collection expressions on an overloaded method #70236

Closed
aradalvand opened this issue Oct 4, 2023 · 2 comments
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@aradalvand
Copy link

aradalvand commented Oct 4, 2023

.NET SDK version: 8.0.100-rc.1.23455.8

This code errs:

Test.Foo(["one", "two"]);

public static class Test
{
    public static void Foo(string str)
    { }

    public static void Foo(IEnumerable<string> strings)
    { }
}

The error message:

The call is ambiguous between the following methods or properties: 'Test.Foo(string)' and 'Test.Foo(IEnumerable)'

Is this somehow by design?! If so then it's going to render the collection expressions feature next to useless for a large portion of use cases.
I upgraded to .NET 8 and was happy to be able to change all array instantiations new[] { ... } into collection expressions, assuming that it would work, but apparently it doesn't.

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

cston commented Oct 4, 2023

@aradalvand, thanks for reporting this issue.

The issue is #69634 which was fixed in #69627.

@aradalvand
Copy link
Author

Ah, good to know. Thanks.

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

No branches or pull requests

2 participants