Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs (C#)

Code before:
                // (7,35): warning CS0168: The variable 'x' is declared but never used
                //         MyExpression<int, string> x;
                Diagnostic(ErrorCode.WRN_UnreferencedVar, "x").WithArguments("x").WithLocation(7, 35));
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24406")]
        public void TestMultipleGenericTypes()
        {
            var text = """
                class MyExpression { }
                class MyExpression<T> { }
                class MyExpression<T1, T2> { }

                class Test
                {
                    void M()
                    {
                        MyExpression<int, string, bool> x;
                    }
                }
                """;

            CreateCompilation(text).VerifyDiagnostics(
                // (9,9): error CS0305: Using the generic type 'MyExpression<T>' requires 1 type arguments
                //         MyExpression<int, string, bool> x;
                Diagnostic(ErrorCode.ERR_BadArity, "MyExpression<int, string, bool>").WithArguments("MyExpression<T>", "type", "1").WithLocation(9, 9),
                // (9,41): warning CS0168: The variable 'x' is declared but never used
                //         MyExpression<int, string, bool> x;
                Diagnostic(ErrorCode.WRN_UnreferencedVar, "x").WithArguments("x").WithLocation(9, 41));
        }
    }
}


Review comment (suggestion):
@copilot Why do we report that `MyExpression<T>` needs 1 type argument, as opposed to `MyExpression<T1, T2>` requires 2 type arguments? What logic is responsible for this choice? #Closed

Code after:
                // (7,35): warning CS0168: The variable 'x' is declared but never used
                //         MyExpression<int, string> x;
                Diagnostic(ErrorCode.WRN_UnreferencedVar, "x").WithArguments("x").WithLocation(7, 35));
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24406")]
        public void TestMultipleGenericTypes()
        {
            var text = """
                class MyExpression { }
                class MyExpression<T> { }
                class MyExpression<T1, T2> { }

                class Test
                {
                    void M()
                    {
                        MyExpression<int, string, bool> x;
                    }
                }
                """;

            CreateCompilation(text).VerifyDiagnostics(
                // (9,9): error CS0305: Using the generic type 'MyExpression<T>' requires 1 type arguments
                //         MyExpression<int, string, bool> x;
                Diagnostic(ErrorCode.ERR_BadArity, "MyExpression<int, string, bool>").WithArguments("MyExpression<T>", "type", "1").WithLocation(9, 9),
                // (9,41): warning CS0168: The variable 'x' is declared but never used
                //         MyExpression<int, string, bool> x;
                Diagnostic(ErrorCode.WRN_UnreferencedVar, "x").WithArguments("x").WithLocation(9, 41));
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24406")]
        public void TestGenericTypeWithNoTypeArguments()
        {
            var text = """
                class MyExpression { }
                class MyExpression<T> { }

                class Test
                {
                    void M()
                    {
                        MyExpression x;
                    }
                }
                """;

            // When both generic and non-generic versions exist and no type arguments are provided,
            // the non-generic version is successfully used (no error expected)
            CreateCompilation(text).VerifyDiagnostics(
                // (8,22): warning CS0168: The variable 'x' is declared but never used