diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs index 6ef384e92ef2f7012c9a8d3a608aba4f841ec5c0..851f7ef92bc3074d3be7c5b72c01584e6ecbb36d 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs @@ -289,26 +289,29 @@ private static ThreeState TryGetBestResult(ArrayBuilder(IQueryable)' requires a receiver of type 'IQueryable' + // file.cs(9,31): error CS0718: 'GC': static types cannot be used as type arguments // var q2 = string.Empty.Cast().Select(x => x); - Diagnostic(ErrorCode.ERR_BadInstanceArgType, "string.Empty").WithArguments("string", "Cast", "System.Linq.Queryable.Cast(System.Linq.IQueryable)", "System.Linq.IQueryable").WithLocation(9, 18), - // file.cs(10,41): error CS1929: 'string' does not contain a definition for 'Cast' and the best extension method overload 'Queryable.Cast(IQueryable)' requires a receiver of type 'IQueryable' + Diagnostic(ErrorCode.ERR_GenericArgIsStaticClass, "Cast").WithArguments("System.GC").WithLocation(9, 31), + // file.cs(10,28): error CS0718: 'GC': static types cannot be used as type arguments // var q1 = /**/from GC x in string.Empty select x/**/; - Diagnostic(ErrorCode.ERR_BadInstanceArgType, "string.Empty").WithArguments("string", "Cast", "System.Linq.Queryable.Cast(System.Linq.IQueryable)", "System.Linq.IQueryable").WithLocation(10, 41) + Diagnostic(ErrorCode.ERR_GenericArgIsStaticClass, "from GC x in string.Empty").WithArguments("System.GC").WithLocation(10, 28) }); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index ce8cdbbfe761d083dc0e1ea511c27573624c75d7..18290139312c5d945ef518ee0652fe5921f153de 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -10488,6 +10488,26 @@ static void Main() new ErrorDescription[] { new ErrorDescription { Code = (int)ErrorCode.ERR_AnonMethGrpInForEach, Line = 7, Column = 27 } }); } + [Fact] + [WorkItem(36203, "https://github.com/dotnet/roslyn/issues/36203")] + public void CS0452_GenericConstraintError_HasHigherPriorityThanMethodOverloadError() + { + var code = @" +class Code +{ + void GenericMethod(int i) where T: class => throw null; + void GenericMethod(string s) => throw null; + + void IncorrectMethodCall() + { + GenericMethod(1); + } +}"; + CreateCompilation(code).VerifyDiagnostics( + // (9,9): error CS0452: The type 'int' must be a reference type in order to use it as parameter 'T' in the generic type or method 'Code.GenericMethod(int)' + Diagnostic(ErrorCode.ERR_RefConstraintNotSatisfied, "GenericMethod").WithArguments("Code.GenericMethod(int)", "T", "int").WithLocation(9, 9)); + } + [Fact] public void CS0457ERR_AmbigUDConv() { @@ -11413,6 +11433,28 @@ public static void Main() new ErrorDescription[] { new ErrorDescription { Code = (int)ErrorCode.ERR_ConvertToStaticClass, Line = 12, Column = 34 } }); } + [Fact] + [WorkItem(36203, "https://github.com/dotnet/roslyn/issues/36203")] + public void CS0718_StaticClassError_HasHigherPriorityThanMethodOverloadError() + { + var code = @" +static class StaticClass { } + +class Code +{ + void GenericMethod(int i) => throw null; + void GenericMethod(string s) => throw null; + + void IncorrectMethodCall() + { + GenericMethod(1); + } +}"; + CreateCompilation(code).VerifyDiagnostics( + // (11,9): error CS0718: 'StaticClass': static types cannot be used as type arguments + Diagnostic(ErrorCode.ERR_GenericArgIsStaticClass, "GenericMethod").WithArguments("StaticClass").WithLocation(11, 9)); + } + [Fact] public void CS0723ERR_VarDeclIsStaticClass_Locals() {