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

Error CS0121 with overloads of params and generic parameters #73422

Closed
ericstj opened this issue May 10, 2024 · 3 comments
Closed

Error CS0121 with overloads of params and generic parameters #73422

ericstj opened this issue May 10, 2024 · 3 comments
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@ericstj
Copy link
Member

ericstj commented May 10, 2024

Version Used:

.NET SDK:
 Version:           9.0.100-preview.3.24204.13
 Commit:            81f61d8290
 Workload version:  9.0.100-manifests.e6dcff2c
 MSBuild version:   17.11.0-preview-24178-16+7ca3c98fa

Steps to Reproduce:

  1. Create two params overloads for a method with a generic parameter as shown below.
  2. In older versions of the compiler, it would choose the better overload as can be seen here: https://sharplab.io/#v2:EYLgtghglgdgNAFxFANnAJiA1AHwAIBMAjALABQeAzAASHUDC1A3udW7TXgCzUCyAFAEpmrdmIBuEAE7VJKagF5qMAKYB3agGUAPLAQA+IQG5RYtgLmCTZMQF9T1B1Vo9e2gCqGADtIhgAztTuANoAutTSAObCTPY27M7cfB7evgFaKWERUtHMcXHkzv4IUgCuAMYIGZ7kLGTktkA===
  3. In the latest version it complains they are ambiguous which forces the caller to allocate the array themselves.

A minimal repro, with source-code provided, is ideal. Using sharplab is preferred for compiler/language issues whenever possible.

using System;
public class C {
    public void M() {
        var val = new S<int>();
        M(val);
    }
    
    public void M<T>(params T[] arg) {}
    public void M<T>(params S<T>[] arg) {}
}

public struct S<T> { }

Diagnostic Id:

If this is a report about a bug in an analyzer, please include the diagnostic if possible (e.g. "IDE0030").

Expected Behavior:
Compiles successfully

Actual Behavior:

error CS0121: The call is ambiguous between the following methods or properties: 'C.M<T>(params T[])' and 'C.M<T>(params S<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 May 10, 2024
ericstj added a commit to dotnet/machinelearning that referenced this issue May 10, 2024
@cston
Copy link
Member

cston commented May 10, 2024

This looks to be a duplicate of #73346.

cc @AlekseyTs to confirm.

ericstj added a commit to dotnet/machinelearning that referenced this issue May 10, 2024
* Update dependencies from https://github.com/dotnet/arcade build 20240419.5

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.SignTool , Microsoft.DotNet.SwaggerGenerator.MSBuild , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitExtensions
 From Version 9.0.0-beta.24212.4 -> To Version 9.0.0-beta.24219.5

* Update dependencies from https://github.com/dotnet/arcade build 20240426.3

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.SignTool , Microsoft.DotNet.SwaggerGenerator.MSBuild , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitExtensions
 From Version 9.0.0-beta.24212.4 -> To Version 9.0.0-beta.24226.3

* Update dependencies from https://github.com/dotnet/arcade build 20240429.1

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.SignTool , Microsoft.DotNet.SwaggerGenerator.MSBuild , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitExtensions
 From Version 9.0.0-beta.24212.4 -> To Version 9.0.0-beta.24229.1

* Update dependencies from https://github.com/dotnet/arcade build 20240503.1

Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.SignTool , Microsoft.DotNet.SwaggerGenerator.MSBuild , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitExtensions
 From Version 9.0.0-beta.24212.4 -> To Version 9.0.0-beta.24253.1

* Workaround false CS0121 with params overloads

dotnet/roslyn#73422

* React to span analyzers and fix a spelling mistake

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Eric StJohn <ericstj@microsoft.com>
@ericstj
Copy link
Member Author

ericstj commented May 10, 2024

Yeah looks like it. Is there a compiler package I could try out to confirm the fix?

@ericstj
Copy link
Member Author

ericstj commented May 10, 2024

@ericstj ericstj closed this as completed May 10, 2024
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