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

Ambigious call in PLinq Aggregate method due to C#10 lambda type inference #56319

Closed
akoeplinger opened this issue Sep 10, 2021 · 3 comments · Fixed by #56341
Closed

Ambigious call in PLinq Aggregate method due to C#10 lambda type inference #56319

akoeplinger opened this issue Sep 10, 2021 · 3 comments · Fixed by #56341

Comments

@akoeplinger
Copy link
Member

Version Used: 4.0.0-5.21453.15 (2bbf85b)

Steps to Reproduce:

  1. Compile https://github.com/dotnet/runtime/blob/91f43669bbd6bdf1ba760a6eaa4e42c2794c5f08/src/libraries/System.Linq.Parallel/tests/QueryOperators/AggregateTests.cs

Expected Behavior: No errors.

Actual Behavior:

AggregateTests.cs(320,59): error CS0121: The call is ambiguous between the following methods or properties: 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, Func<TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' and 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' [/Users/alexander/dev/runtime/src/libraries/System.Linq.Parallel/tests/System.Linq.Parallel.Tests.csproj]
AggregateTests.cs(333,93): error CS0121: The call is ambiguous between the following methods or properties: 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, Func<TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' and 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' [/Users/alexander/dev/runtime/src/libraries/System.Linq.Parallel/tests/System.Linq.Parallel.Tests.csproj]
AggregateTests.cs(338,97): error CS0121: The call is ambiguous between the following methods or properties: 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, Func<TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' and 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' [/Users/alexander/dev/runtime/src/libraries/System.Linq.Parallel/tests/System.Linq.Parallel.Tests.csproj]
AggregateTests.cs(360,103): error CS0121: The call is ambiguous between the following methods or properties: 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, Func<TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' and 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' [/Users/alexander/dev/runtime/src/libraries/System.Linq.Parallel/tests/System.Linq.Parallel.Tests.csproj]
AggregateTests.cs(362,119): error CS0121: The call is ambiguous between the following methods or properties: 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, Func<TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' and 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' [/Users/alexander/dev/runtime/src/libraries/System.Linq.Parallel/tests/System.Linq.Parallel.Tests.csproj]
AggregateTests.cs(363,121): error CS0121: The call is ambiguous between the following methods or properties: 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, Func<TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' and 'ParallelEnumerable.Aggregate<TSource, TAccumulate, TResult>(ParallelQuery<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TAccumulate, TAccumulate>, Func<TAccumulate, TResult>)' [/Users/alexander/dev/runtime/src/libraries/System.Linq.Parallel/tests/System.Linq.Parallel.Tests.csproj]

@CyrusNajmabadi asked me to open an issue for discussion.

/cc @333fred @cston

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

cston commented Sep 10, 2021

The ambiguities should be resolved in dotnet/runtime#58953.

@CyrusNajmabadi
Copy link
Member

Note: using @AlekseyTs 's formalization from yesterday, i don't think this would be a break. We would still bind with the original meaning, and only fall back to the new meaning if htat fails.

@CyrusNajmabadi
Copy link
Member

@cston i don't like that approach as i think the original code they have is reasonable and they shouldn't have to add explicit types to workaround it. The particular example is somewhat egregious as i think the language is sliding backwards here. Specifically, given teh type Func<int> it seems wrong to me that an instantiation of T -> Func<int> is treated as good as an instantiation of Func<T> -> Func<int>. The latter seems to intuitively be what someone would want and expect. Even if T -> Func<int> is a possible inference, it should not be as good as Func<T> -> Func<int>. I think we should revisit this and not have people have to provide parametr types in cases like these.

Note that linq is a high pri api that we should endeavor to keep working IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment