Skip to content

ambiguous between in Add(TValue) and Add(params IEnumerable<TValue>) #80512

@zms9110750

Description

@zms9110750

Version Used:
Visual Studio Community 2022 - 17.14.16

Steps to Reproduce:

.NET Lab

  1. Define the following types:
    interface ITree<TV, TNode> where TNode : ITree<TV, TNode>;
    class Tree<T> : ITree<T, Tree<T>>;
  2. Create an extension method with two overloads:
    static class P
    {
        extension<TV, TN>(ITree<TV, TN> node) where TN : ITree<TV, TN>
        {
            public void Add(TV value) { }
            public void Add(params TV[] values) { }
        }
    }
  3. Try to call Add with a single argument:
    Tree<int> b = new Tree<int>();
    b.Add(1); // CS0121: Ambiguous call between 'Add(TV)' and 'Add(params TV[])'

Expected Behavior:
The compiler should resolve b.Add(1) to the non-params overload (Add(TV)), since it has a fixed number of arguments.

Actual Behavior:
Compiler error CS0121 occurs, indicating ambiguity between Add(TV) and Add(params TV[]).

Diagnostic Id:
CS0121 (The call is ambiguous between the following methods or properties)

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions