提交 97c4a9f1 编写于 作者: A acasey

DevDiv #906494: Overload resolution diagnostic reporting

We were throwing unreachable when we fell out the bottom of some complicated error handling code and Tomas hit it while dogfooding.  We were unable to determine the path that resulted in the crash, but there were enough problems that a more comprehensive cleanup seemed desirable.  The catch-all diagnostic is now checked last and actually serves as a catch-all.

Miscellaneous improvements:
1) Eliminated MemberCouldTakeArgumentCount which was trying to approximate overload resolution.
2) Standardized mechanism for iterating of list of candidates.
3) Eliminated MemberResolutionKind.BadGenericArity.  Comments explicitly stated that it was never used.

CR: AlekseyT (changeset 1211059)
上级 42097417
......@@ -125,7 +125,6 @@ private static bool SuppressUseSiteDiagnosticsForKind(MemberResolutionKind kind)
{
case MemberResolutionKind.UnsupportedMetadata:
return true;
case MemberResolutionKind.BadGenericArity:
case MemberResolutionKind.NoCorrespondingParameter:
case MemberResolutionKind.NoCorrespondingNamedParameter:
case MemberResolutionKind.NameUsedForPositional:
......@@ -230,11 +229,6 @@ public static MemberAnalysisResult TypeInferenceExtensionInstanceArgumentFailed(
return new MemberAnalysisResult(MemberResolutionKind.TypeInferenceExtensionInstanceArgument);
}
public static MemberAnalysisResult BadGenericArity()
{
return new MemberAnalysisResult(MemberResolutionKind.BadGenericArity);
}
public static MemberAnalysisResult ConstructedParameterFailedConstraintsCheck(int parameterPosition)
{
return new MemberAnalysisResult(
......
......@@ -87,11 +87,6 @@ internal enum MemberResolutionKind : byte
/// </summary>
TypeInferenceExtensionInstanceArgument,
/// <summary>
/// The candidate member was rejected because it had the wrong number of type parameters.
/// </summary>
BadGenericArity,
/// <summary>
/// The candidate member was rejected because it a constraint on a type parameter was not satisfied.
/// </summary>
......@@ -104,7 +99,7 @@ internal enum MemberResolutionKind : byte
LessDerived,
/// <summary>
/// The candidate member was rejected because it was considered worse that another member (according to sectino
/// The candidate member was rejected because it was considered worse that another member (according to section
/// 7.5.3.2 of the language specification).
/// </summary>
Worse,
......
......@@ -124,48 +124,6 @@ private static CommonMemberResolutionKind ConvertKind(MemberResolutionKind kind)
}
}
internal bool MemberCouldTakeArgumentCount(int count)
{
bool isVararg = leastOverriddenMember.GetIsVararg();
int parameterCount = leastOverriddenMember.GetParameterCount() + (isVararg ? 1 : 0);
// Early out.
if (parameterCount == count)
{
return true;
}
int optionalParameters = 0;
// Allow for any optional parameters, although if the method
// is vararg, optional parameters are not optional.
if (!isVararg)
{
foreach (ParameterSymbol param in leastOverriddenMember.GetParameters())
{
if (param.IsOptional)
{
optionalParameters += 1;
}
}
}
if (OverloadResolution.IsValidParams(leastOverriddenMember))
{
if (parameterCount - optionalParameters - 1 <= count)
{
return true;
}
}
else
{
if (parameterCount - optionalParameters <= count && count <= parameterCount)
{
return true;
}
}
return false;
}
public override bool Equals(object obj)
{
throw new NotSupportedException();
......
......@@ -459,30 +459,15 @@ private MemberAnalysisResult IsConstructorApplicableInExpandedForm(MethodSymbol
return;
}
var typeArgumentCount = typeArguments.Count;
// First deal with eliminating generic-arity mismatches.
// SPEC: If F is generic and M includes a type argument list, F is a candidate when:
// SPEC: * F has the same number of method type parameters as were supplied in the type argument list, and
//
// This is specifying an impossible condition; the member lookup
// algorithm has already filtered out methods from the method group that have the wrong
// generic arity. However, we'll keep the "bad generic arity" error condition around because
// in the future we might want to add methods that are *not* in the method group to the
// overload resolution results list, to give more complete results.
if (typeArgumentCount > 0 && typeArgumentCount != member.GetMemberArity())
{
Debug.Assert(false, "How did we get a method of bad generic arity in the method group?");
Debug.Assert(!MemberAnalysisResult.BadGenericArity().HasUseSiteDiagnosticToReportFor(member)); // No need to store.
if (completeResults)
{
results.Add(new MemberResolutionResult<TMember>(member, leastOverriddenMember, MemberAnalysisResult.BadGenericArity()));
}
// This is specifying an impossible condition; the member lookup algorithm has already filtered
// out methods from the method group that have the wrong generic arity.
return;
}
Debug.Assert(typeArguments.Count == 0 || typeArguments.Count == member.GetMemberArity());
// Second, we need to determine if the method is applicable in its normal form or its expanded form.
......
......@@ -3791,9 +3791,9 @@ public static void Main()
compilation.VerifyDiagnostics(
// (3,39): error CS0643: 'AllowMultiple' duplicate named attribute argument
Diagnostic(ErrorCode.ERR_DuplicateNamedAttributeArgument, "AllowMultiple = false").WithArguments("AllowMultiple"),
// (3,2): error CS1729: 'System.AttributeUsageAttribute' does not contain a constructor that takes 0 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "AttributeUsage(AllowMultiple = true, AllowMultiple = false)").WithArguments("System.AttributeUsageAttribute", "0"));
Diagnostic(ErrorCode.ERR_DuplicateNamedAttributeArgument, "AllowMultiple = false").WithArguments("AllowMultiple").WithLocation(3, 39),
// (3,2): error CS7036: There is no argument given that corresponds to the required formal parameter 'validOn' of 'System.AttributeUsageAttribute.AttributeUsageAttribute(System.AttributeTargets)'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "AttributeUsage(AllowMultiple = true, AllowMultiple = false)").WithArguments("validOn", "System.AttributeUsageAttribute.AttributeUsageAttribute(System.AttributeTargets)").WithLocation(3, 2));
}
[WorkItem(541059)]
......
......@@ -179,21 +179,21 @@ public class C
}";
var compilation = CreateCompilationWithMscorlib(source);
compilation.VerifyDiagnostics(
// (9,6): error CS1729: 'System.Security.Permissions.PrincipalPermissionAttribute' does not contain a constructor that takes 0 arguments
// (9,6): error CS7036: There is no argument given that corresponds to the required formal parameter 'action' of 'System.Security.Permissions.PrincipalPermissionAttribute.PrincipalPermissionAttribute(System.Security.Permissions.SecurityAction)'
// [PrincipalPermission()] // Invalid attribute constructor
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "PrincipalPermission()").WithArguments("System.Security.Permissions.PrincipalPermissionAttribute", "0"),
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "PrincipalPermission()").WithArguments("action", "System.Security.Permissions.PrincipalPermissionAttribute.PrincipalPermissionAttribute(System.Security.Permissions.SecurityAction)").WithLocation(9, 6),
// (6,26): error CS7049: Security attribute 'PrincipalPermission' has an invalid SecurityAction value '(SecurityAction)0'
// [PrincipalPermission((SecurityAction)0)] // Invalid attribute argument
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)0").WithArguments("PrincipalPermission", "(SecurityAction)0"),
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)0").WithArguments("PrincipalPermission", "(SecurityAction)0").WithLocation(6, 26),
// (7,26): error CS7049: Security attribute 'PrincipalPermission' has an invalid SecurityAction value '(SecurityAction)11'
// [PrincipalPermission((SecurityAction)11)] // Invalid attribute argument
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)11").WithArguments("PrincipalPermission", "(SecurityAction)11"),
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)11").WithArguments("PrincipalPermission", "(SecurityAction)11").WithLocation(7, 26),
// (8,26): error CS7049: Security attribute 'PrincipalPermission' has an invalid SecurityAction value '(SecurityAction)(-1)'
// [PrincipalPermission((SecurityAction)(-1))] // Invalid attribute argument
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)(-1)").WithArguments("PrincipalPermission", "(SecurityAction)(-1)"),
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)(-1)").WithArguments("PrincipalPermission", "(SecurityAction)(-1)").WithLocation(8, 26),
// (12,10): error CS0592: Attribute 'PrincipalPermission' is not valid on this declaration type. It is only valid on 'class, method' declarations.
// [PrincipalPermission(SecurityAction.Demand)] // Invalid attribute target
Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "PrincipalPermission").WithArguments("PrincipalPermission", "class, method"));
Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "PrincipalPermission").WithArguments("PrincipalPermission", "class, method").WithLocation(12, 10));
}
[WorkItem(544918)]
......@@ -225,19 +225,19 @@ public class C
compilation.VerifyDiagnostics(
// (12,26): error CS7049: Security attribute 'MySecurityAttribute' has an invalid SecurityAction value '(SecurityAction)0'
// [MySecurityAttribute((SecurityAction)0)] // Invalid attribute argument
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)0").WithArguments("MySecurityAttribute", "(SecurityAction)0"),
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)0").WithArguments("MySecurityAttribute", "(SecurityAction)0").WithLocation(12, 26),
// (13,26): error CS7049: Security attribute 'MySecurityAttribute' has an invalid SecurityAction value '(SecurityAction)11'
// [MySecurityAttribute((SecurityAction)11)] // Invalid attribute argument
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)11").WithArguments("MySecurityAttribute", "(SecurityAction)11"),
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)11").WithArguments("MySecurityAttribute", "(SecurityAction)11").WithLocation(13, 26),
// (14,26): error CS7049: Security attribute 'MySecurityAttribute' has an invalid SecurityAction value '(SecurityAction)(-1)'
// [MySecurityAttribute((SecurityAction)(-1))] // Invalid attribute argument
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)(-1)").WithArguments("MySecurityAttribute", "(SecurityAction)(-1)"),
// (15,6): error CS1729: 'MySecurityAttribute' does not contain a constructor that takes 0 arguments
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "(SecurityAction)(-1)").WithArguments("MySecurityAttribute", "(SecurityAction)(-1)").WithLocation(14, 26),
// (15,6): error CS7036: There is no argument given that corresponds to the required formal parameter 'action' of 'MySecurityAttribute.MySecurityAttribute(System.Security.Permissions.SecurityAction)'
// [MySecurityAttribute()] // Invalid attribute constructor
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "MySecurityAttribute()").WithArguments("MySecurityAttribute", "0"),
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "MySecurityAttribute()").WithArguments("action", "MySecurityAttribute.MySecurityAttribute(System.Security.Permissions.SecurityAction)").WithLocation(15, 6),
// (18,10): error CS0592: Attribute 'MySecurityAttribute' is not valid on this declaration type. It is only valid on 'assembly, class, struct, constructor, method' declarations.
// [MySecurityAttribute(SecurityAction.Demand)] // Invalid attribute target
Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "MySecurityAttribute").WithArguments("MySecurityAttribute", "assembly, class, struct, constructor, method"));
Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "MySecurityAttribute").WithArguments("MySecurityAttribute", "assembly, class, struct, constructor, method").WithLocation(18, 10));
}
[WorkItem(544918)]
......
......@@ -1102,10 +1102,10 @@ public class Foo: Attribute
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (15,17): warning CS0436: The type 'System.Runtime.InteropServices.OptionalAttribute' in '' conflicts with the imported type 'System.Runtime.InteropServices.OptionalAttribute' in 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using the type defined in ''.
// public Foo([Optional(isOpt: false)][Foo]int y) {}
Diagnostic(ErrorCode.WRN_SameFullNameThisAggAgg, "Optional").WithArguments("", "System.Runtime.InteropServices.OptionalAttribute", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Runtime.InteropServices.OptionalAttribute"),
// (15,41): error CS1729: 'Foo' does not contain a constructor that takes 0 arguments
Diagnostic(ErrorCode.WRN_SameFullNameThisAggAgg, "Optional").WithArguments("", "System.Runtime.InteropServices.OptionalAttribute", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Runtime.InteropServices.OptionalAttribute").WithLocation(15, 17),
// (15,41): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'Foo.Foo(int)'
// public Foo([Optional(isOpt: false)][Foo]int y) {}
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Foo").WithArguments("Foo", "0"));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Foo").WithArguments("y", "Foo.Foo(int)").WithLocation(15, 41));
}
[Fact]
......@@ -1164,13 +1164,13 @@ public class Foo: Attribute
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (16,17): warning CS0436: The type 'System.Runtime.InteropServices.OptionalAttribute' in '' conflicts with the imported type 'System.Runtime.InteropServices.OptionalAttribute' in 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using the type defined in ''.
// public Foo([Optional(new Foo())][Foo]int y) {}
Diagnostic(ErrorCode.WRN_SameFullNameThisAggAgg, "Optional").WithArguments("", "System.Runtime.InteropServices.OptionalAttribute", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Runtime.InteropServices.OptionalAttribute"),
// (16,30): error CS1729: 'Foo' does not contain a constructor that takes 0 arguments
Diagnostic(ErrorCode.WRN_SameFullNameThisAggAgg, "Optional").WithArguments("", "System.Runtime.InteropServices.OptionalAttribute", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Runtime.InteropServices.OptionalAttribute").WithLocation(16, 17),
// (16,30): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'Foo.Foo(int)'
// public Foo([Optional(new Foo())][Foo]int y) {}
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Foo").WithArguments("Foo", "0"),
// (16,38): error CS1729: 'Foo' does not contain a constructor that takes 0 arguments
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Foo").WithArguments("y", "Foo.Foo(int)").WithLocation(16, 30),
// (16,38): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'Foo.Foo(int)'
// public Foo([Optional(new Foo())][Foo]int y) {}
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Foo").WithArguments("Foo", "0"));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Foo").WithArguments("y", "Foo.Foo(int)").WithLocation(16, 38));
}
[Fact, WorkItem(546624)]
......@@ -4917,9 +4917,9 @@ public void TestComCompatibleVersionAttribute_Invalid_02()
[assembly: ComCompatibleVersionAttribute(""str"", 0)]
";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (4,12): error CS1729: 'System.Runtime.InteropServices.ComCompatibleVersionAttribute' does not contain a constructor that takes 2 arguments
// (4,12): error CS7036: There is no argument given that corresponds to the required formal parameter 'build' of 'System.Runtime.InteropServices.ComCompatibleVersionAttribute.ComCompatibleVersionAttribute(int, int, int, int)'
// [assembly: ComCompatibleVersionAttribute("str", 0)]
Diagnostic(ErrorCode.ERR_BadCtorArgCount, @"ComCompatibleVersionAttribute(""str"", 0)").WithArguments("System.Runtime.InteropServices.ComCompatibleVersionAttribute", "2"));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, @"ComCompatibleVersionAttribute(""str"", 0)").WithArguments("build", "System.Runtime.InteropServices.ComCompatibleVersionAttribute.ComCompatibleVersionAttribute(int, int, int, int)").WithLocation(4, 12));
}
#endregion
......
......@@ -1486,12 +1486,12 @@ void Test()
assemblyName: "asm3");
comp3.VerifyDiagnostics(
// (7,9): error CS1501: No overload for method 'F' takes 0 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "c.F").WithArguments("F", "0"),
// (7,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'a' of 'B.F(int[])'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "c.F").WithArguments("a", "B.F(int[])").WithLocation(7, 9),
// (8,20): error CS1061: 'object' does not contain a definition for 'Bar' and no extension method 'Bar' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "Bar").WithArguments("object", "Bar"),
// (10,17): error CS1501: No overload for method 'this' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "c[1]").WithArguments("this", "1"));
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "Bar").WithArguments("object", "Bar").WithLocation(8, 20),
// (10,17): error CS7036: There is no argument given that corresponds to the required formal parameter 'a' of 'B.this[int, int[]]'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "c[1]").WithArguments("a", "B.this[int, int[]]").WithLocation(10, 17));
}
[Fact] [WorkItem(529779)]
......
......@@ -460,52 +460,51 @@ public class MyAttribute : System.Attribute
var comp = CreateCompilationWithMscorlib(text);
comp.VerifyDiagnostics(
// (5,26): error CS1669: __arglist is not valid in this context
// static void N(params __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist"),
// (6,23): error CS1669: __arglist is not valid in this context
// static void O(ref __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist"),
// (7,23): error CS1669: __arglist is not valid in this context
// static void P(out __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist"),
// (8,24): error CS1669: __arglist is not valid in this context
// static void Q(this __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist"),
// (11,9): error CS1501: No overload for method 'M' takes 1 arguments
// M(1);
Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "1"),
// (12,14): error CS1503: Argument 2: cannot convert from 'int' to '__arglist'
// M(2, 3);
Diagnostic(ErrorCode.ERR_BadArgType, "3").WithArguments("2", "int", "__arglist"),
// (13,9): error CS1501: No overload for method 'M' takes 3 arguments
// M(4, 5, 6);
Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "3"),
// (15,24): error CS0226: An __arglist expression may only appear inside of a call or new expression
// M(1, __arglist(__arglist()));
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist()"),
// (16,17): error CS0226: An __arglist expression may only appear inside of a call or new expression
// var x = __arglist(123);
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist(123)"),
// (20,16): error CS0226: An __arglist expression may only appear inside of a call or new expression
// return __arglist(456);
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist(456)"),
// (24,11): error CS1503: Argument 1: cannot convert from '__arglist' to 'int'
// S(__arglist(1));
Diagnostic(ErrorCode.ERR_BadArgType, "__arglist(1)").WithArguments("1", "__arglist", "int"),
// (27,18): error CS0226: An __arglist expression may only appear inside of a call or new expression
// [MyAttribute(__arglist(2))]
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist(2)"),
// (30,23): error CS0029: Cannot implicitly convert type 'System.TypedReference' to 'object'
// object obj1 = new System.TypedReference();
Diagnostic(ErrorCode.ERR_NoImplicitConv, "new System.TypedReference()").WithArguments("System.TypedReference", "object"),
// (31,23): error CS0030: Cannot convert type 'System.ArgIterator' to 'object'
// object obj2
Diagnostic(ErrorCode.ERR_NoExplicitConv, "(object)new System.ArgIterator()").WithArguments("System.ArgIterator", "object"),
// (38,29): error CS0828: Cannot assign System.TypedReference to anonymous type property
// object obj3 = new { X = new System.TypedReference() };
Diagnostic(ErrorCode.ERR_AnonymousTypePropertyAssignedBadValue, "X = new System.TypedReference()").WithArguments("System.TypedReference")
);
// (5,26): error CS1669: __arglist is not valid in this context
// static void N(params __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist").WithLocation(5, 26),
// (6,23): error CS1669: __arglist is not valid in this context
// static void O(ref __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist").WithLocation(6, 23),
// (7,23): error CS1669: __arglist is not valid in this context
// static void P(out __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist").WithLocation(7, 23),
// (8,24): error CS1669: __arglist is not valid in this context
// static void Q(this __arglist) {}
Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist").WithLocation(8, 24),
// (11,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'C.M(int, __arglist)'
// M(1);
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "M").WithArguments("__arglist", "C.M(int, __arglist)").WithLocation(11, 9),
// (12,14): error CS1503: Argument 2: cannot convert from 'int' to '__arglist'
// M(2, 3);
Diagnostic(ErrorCode.ERR_BadArgType, "3").WithArguments("2", "int", "__arglist").WithLocation(12, 14),
// (13,9): error CS1501: No overload for method 'M' takes 3 arguments
// M(4, 5, 6);
Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "3").WithLocation(13, 9),
// (15,24): error CS0226: An __arglist expression may only appear inside of a call or new expression
// M(1, __arglist(__arglist()));
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist()").WithLocation(15, 24),
// (16,17): error CS0226: An __arglist expression may only appear inside of a call or new expression
// var x = __arglist(123);
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist(123)").WithLocation(16, 17),
// (20,16): error CS0226: An __arglist expression may only appear inside of a call or new expression
// return __arglist(456);
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist(456)").WithLocation(20, 16),
// (24,11): error CS1503: Argument 1: cannot convert from '__arglist' to 'int'
// S(__arglist(1));
Diagnostic(ErrorCode.ERR_BadArgType, "__arglist(1)").WithArguments("1", "__arglist", "int").WithLocation(24, 11),
// (27,18): error CS0226: An __arglist expression may only appear inside of a call or new expression
// [MyAttribute(__arglist(2))]
Diagnostic(ErrorCode.ERR_IllegalArglist, "__arglist(2)").WithLocation(27, 18),
// (30,23): error CS0029: Cannot implicitly convert type 'System.TypedReference' to 'object'
// object obj1 = new System.TypedReference();
Diagnostic(ErrorCode.ERR_NoImplicitConv, "new System.TypedReference()").WithArguments("System.TypedReference", "object").WithLocation(30, 23),
// (31,23): error CS0030: Cannot convert type 'System.ArgIterator' to 'object'
// object obj2 = (object)new System.ArgIterator();
Diagnostic(ErrorCode.ERR_NoExplicitConv, "(object)new System.ArgIterator()").WithArguments("System.ArgIterator", "object").WithLocation(31, 23),
// (38,29): error CS0828: Cannot assign System.TypedReference to anonymous type property
// object obj3 = new { X = new System.TypedReference() };
Diagnostic(ErrorCode.ERR_AnonymousTypePropertyAssignedBadValue, "X = new System.TypedReference()").WithArguments("System.TypedReference").WithLocation(38, 29));
}
[Fact]
......@@ -1296,30 +1295,42 @@ static void M()
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (26,9): error CS1729: 'A' does not contain a constructor that takes 1 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "A").WithArguments("A", "1").WithLocation(26, 13),
// (28,9): error CS1501: No overload for method 'M' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "A.M").WithArguments("M", "1").WithLocation(28, 9),
// (31,9): error CS1729: 'B' does not contain a constructor that takes 1 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "B").WithArguments("B", "1").WithLocation(31, 13),
// (33,9): error CS1501: No overload for method 'M' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "B.M").WithArguments("M", "1").WithLocation(33, 9),
// (36,9): error CS1729: 'C' does not contain a constructor that takes 1 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "C").WithArguments("C", "1").WithLocation(36, 13),
// (37,9): error CS1729: 'C' does not contain a constructor that takes 2 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "C").WithArguments("C", "2").WithLocation(37, 13),
// (39,9): error CS1501: No overload for method 'M' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "C.M").WithArguments("M", "1").WithLocation(39, 9),
// (40,9): error CS1501: No overload for method 'M' takes 2 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "C.M").WithArguments("M", "2").WithLocation(40, 9),
// (43,9): error CS1729: 'D' does not contain a constructor that takes 1 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "D").WithArguments("D", "1").WithLocation(43, 13),
// (44,9): error CS1729: 'D' does not contain a constructor that takes 2 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "D").WithArguments("D", "2").WithLocation(44, 13),
// (46,9): error CS1501: No overload for method 'M' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "D.M").WithArguments("M", "1").WithLocation(46, 9),
// (47,9): error CS1501: No overload for method 'M' takes 2 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "D.M").WithArguments("M", "2").WithLocation(47, 9));
// (26,13): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'A.A(object, __arglist)'
// new A(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "A").WithArguments("__arglist", "A.A(object, __arglist)").WithLocation(26, 13),
// (28,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'A.M(object, __arglist)'
// A.M(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "A.M").WithArguments("__arglist", "A.M(object, __arglist)").WithLocation(28, 9),
// (31,13): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'B.B(object, __arglist)'
// new B(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "B").WithArguments("__arglist", "B.B(object, __arglist)").WithLocation(31, 13),
// (33,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'B.M(object, __arglist)'
// B.M(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "B.M").WithArguments("__arglist", "B.M(object, __arglist)").WithLocation(33, 9),
// (36,13): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'C.C(object, object, __arglist)'
// new C(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "C").WithArguments("__arglist", "C.C(object, object, __arglist)").WithLocation(36, 13),
// (37,13): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'C.C(object, object, __arglist)'
// new C(null, __arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "C").WithArguments("__arglist", "C.C(object, object, __arglist)").WithLocation(37, 13),
// (39,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'C.M(object, object, __arglist)'
// C.M(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "C.M").WithArguments("__arglist", "C.M(object, object, __arglist)").WithLocation(39, 9),
// (40,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'C.M(object, object, __arglist)'
// C.M(null, __arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "C.M").WithArguments("__arglist", "C.M(object, object, __arglist)").WithLocation(40, 9),
// (43,13): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'D.D(object, object, __arglist)'
// new D(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "D").WithArguments("__arglist", "D.D(object, object, __arglist)").WithLocation(43, 13),
// (44,13): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'D.D(object, object, __arglist)'
// new D(null, __arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "D").WithArguments("__arglist", "D.D(object, object, __arglist)").WithLocation(44, 13),
// (46,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'D.M(object, object, __arglist)'
// D.M(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "D.M").WithArguments("__arglist", "D.M(object, object, __arglist)").WithLocation(46, 9),
// (47,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'D.M(object, object, __arglist)'
// D.M(null, __arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "D.M").WithArguments("__arglist", "D.M(object, object, __arglist)").WithLocation(47, 9));
}
[WorkItem(649808)]
......@@ -1345,8 +1356,9 @@ static void M(D d)
}";
var compilation = CreateCompilationWithCustomILSource(source, ilSource);
compilation.VerifyDiagnostics(
// (6, 9): error CS1593: Delegate 'D' does not take 1 arguments
Diagnostic(ErrorCode.ERR_BadDelArgCount, "d").WithArguments("D", "1").WithLocation(6, 9));
// (6,9): error CS7036: There is no argument given that corresponds to the required formal parameter '__arglist' of 'D'
// d(__arglist());
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "d").WithArguments("__arglist", "D").WithLocation(6, 9));
}
}
}
\ No newline at end of file
......@@ -1507,19 +1507,18 @@ public static Awaiter GetAwaiter(this D a, object o)
}
}";
CreateCompilationWithMscorlib45(source).VerifyDiagnostics(
// (10,9): error CS1986: 'await' requires that the type A have a suitable GetAwaiter method
// await new A();
Diagnostic(ErrorCode.ERR_BadAwaitArg, "await new A()").WithArguments("A"),
// (11,9): error CS1501: No overload for method 'GetAwaiter' takes 0 arguments
// await new B();
Diagnostic(ErrorCode.ERR_BadArgCount, "await new B()").WithArguments("GetAwaiter", "0"),
// (12,9): error CS1986: 'await' requires that the type C have a suitable GetAwaiter method
// await new C();
Diagnostic(ErrorCode.ERR_BadAwaitArg, "await new C()").WithArguments("C"),
// (13,15): error CS1929: 'D' does not contain a definition for 'GetAwaiter' and the best extension method overload 'MyExtensions.GetAwaiter(C, object)' requires a receiver of type 'C'
// await new D();
Diagnostic(ErrorCode.ERR_BadInstanceArgType, "new D()").WithArguments("D", "GetAwaiter", "MyExtensions.GetAwaiter(C, object)", "C")
);
// (10,9): error CS1986: 'await' requires that the type A have a suitable GetAwaiter method
// await new A();
Diagnostic(ErrorCode.ERR_BadAwaitArg, "await new A()").WithArguments("A").WithLocation(10, 9),
// (11,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'o' of 'B.GetAwaiter(object)'
// await new B();
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "await new B()").WithArguments("o", "B.GetAwaiter(object)").WithLocation(11, 9),
// (12,9): error CS1986: 'await' requires that the type C have a suitable GetAwaiter method
// await new C();
Diagnostic(ErrorCode.ERR_BadAwaitArg, "await new C()").WithArguments("C").WithLocation(12, 9),
// (13,15): error CS1929: 'D' does not contain a definition for 'GetAwaiter' and the best extension method overload 'MyExtensions.GetAwaiter(C, object)' requires a receiver of type 'C'
// await new D();
Diagnostic(ErrorCode.ERR_BadInstanceArgType, "new D()").WithArguments("D", "GetAwaiter", "MyExtensions.GetAwaiter(C, object)", "C").WithLocation(13, 15));
}
[Fact]
......
......@@ -615,8 +615,8 @@ static void M(object o)
static void F(int i, params int[] args) { }
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (5,9): error CS1501: No overload for method 'F' takes 0 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "F").WithArguments("F", "0").WithLocation(5, 9),
// (5,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'i' of 'C.F(int, params int[])'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "F").WithArguments("i", "C.F(int, params int[])").WithLocation(5, 9),
// (6,11): error CS1503: Argument 1: cannot convert from 'object' to 'int'
Diagnostic(ErrorCode.ERR_BadArgType, "o").WithArguments("1", "object", "int").WithLocation(6, 11),
// (7,14): error CS1503: Argument 2: cannot convert from 'object' to 'int'
......
......@@ -3077,9 +3077,9 @@ C M(dynamic d)
TestOperatorKinds(source);
var comp = CreateCompilationWithMscorlibAndSystemCore(source);
comp.VerifyDiagnostics(
// (8,16): error CS1729: 'C' does not contain a constructor that takes 1 arguments
// (8,16): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'C.C(string, string)'
// return new C(d);
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "C").WithArguments("C", "1"));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "C").WithArguments("y", "C.C(string, string)").WithLocation(8, 16));
}
[Fact]
......
......@@ -1335,9 +1335,9 @@ static void Main()
}
";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (25,9): error CS1501: No overload for method 'M' takes 0 arguments
// (25,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'o' of 'D.M(ref object)'
// d.M(); //CS1501
Diagnostic(ErrorCode.ERR_BadArgCount, "d.M").WithArguments("M", "0").WithLocation(25, 9));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "d.M").WithArguments("o", "D.M(ref object)").WithLocation(25, 9));
}
[WorkItem(545337)]
......
......@@ -412,7 +412,7 @@ static void M()
"'p.Generic' error CS0411: The type arguments for method 'P.Generic<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.",
"'NotGeneric<int, int>' error CS0308: The non-generic method 'P.NotGeneric()' cannot be used with type arguments",
"'Generic<int, int>' error CS0305: Using the generic method 'P.Generic<T>()' requires 1 type arguments",
"'p.NoParameter' error CS1501: No overload for method 'NoParameter' takes 1 arguments",
"'frob' error CS1739: The best overload for 'NoParameter' does not have a parameter named 'frob'",
"'p.NoParameter' error CS1501: No overload for method 'NoParameter' takes 2 arguments",
"'p.StaticMethod' error CS0176: Member 'P.StaticMethod()' cannot be accessed with an instance reference; qualify it with a type name instead",
"'P.NoParameter' error CS0120: An object reference is required for the non-static field, method, or property 'P.NoParameter()'",
......
......@@ -11920,8 +11920,8 @@ static void M(I i)
compilation2.VerifyDiagnostics(
// (8,9): error CS0856: Indexed property 'I.R' has non-optional arguments which must be provided
Diagnostic(ErrorCode.ERR_IndexedPropertyRequiresParams, "i.R").WithArguments("I.R").WithLocation(8, 9),
// (9,9): error CS1501: No overload for method 'R' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "i.R[1]").WithArguments("R", "1").WithLocation(9, 9));
// (9,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'I.R[int, int, int]'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "i.R[1]").WithArguments("y", "I.R[int, int, int]").WithLocation(9, 9));
}
[Fact]
......@@ -13207,8 +13207,10 @@ static void Main(string[] args)
}
}
";
CreateCompilationWithMscorlib(text).
VerifyDiagnostics(Diagnostic(ErrorCode.ERR_BadDelArgCount, "md1").WithArguments("MyDelegate1", "1"));
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (11,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'MyDelegate1'
// md1(1);
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "md1").WithArguments("y", "MyDelegate1").WithLocation(11, 9));
}
......@@ -14860,19 +14862,18 @@ public Child2(int k)
}
}";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (21,14): error CS1729: 'Parent' does not contain a constructor that takes 0 arguments
// (21,14): error CS7036: There is no argument given that corresponds to the required formal parameter 'i' of 'Parent.Parent(int, int)'
// public class Child : Parent { } // CS1729
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Child").WithArguments("Parent", "0"),
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Child").WithArguments("i", "Parent.Parent(int, int)").WithLocation(21, 14),
// (6,24): error CS1729: 'double' does not contain a constructor that takes 1 arguments
// double d = new double(4.5); // was CS0143 (Dev10)
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "double").WithArguments("double", "1"),
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "double").WithArguments("double", "1").WithLocation(6, 24),
// (7,26): error CS1729: 'Test' does not contain a constructor that takes 1 arguments
// Test test1 = new Test(2); // CS1729
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test").WithArguments("Test", "1"),
// (9,37): error CS1729: 'Parent' does not contain a constructor that takes 1 arguments
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test").WithArguments("Test", "1").WithLocation(7, 26),
// (9,37): error CS7036: There is no argument given that corresponds to the required formal parameter 'j' of 'Parent.Parent(int, int)'
// Parent exampleParent1 = new Parent(10); // CS1729
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Parent").WithArguments("Parent", "1")
);
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Parent").WithArguments("j", "Parent.Parent(int, int)").WithLocation(9, 37));
}
[WorkItem(539631)]
......
......@@ -853,15 +853,15 @@ static object F(int i)
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (6,17): error CS0166: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
// (6,17): error CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
// switch (o)
Diagnostic(ErrorCode.ERR_SwitchGoverningTypeValueExpected, "o").WithLocation(6, 17),
// (8,20): error CS1503: Argument 1: cannot convert from '<null>' to 'int'
// case F(null):
Diagnostic(ErrorCode.ERR_BadArgType, "null").WithArguments("1", "<null>", "int").WithLocation(8, 20),
// (9,17): error CS1501: No overload for method 'M' takes 0 arguments
// (9,17): error CS7036: There is no argument given that corresponds to the required formal parameter 'o' of 'C.M(object)'
// M();
Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "0").WithLocation(9, 17));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "M").WithArguments("o", "C.M(object)").WithLocation(9, 17));
}
[Fact]
......
......@@ -589,7 +589,7 @@ void M()
this.M2(1); // MethodResolutionKind.RequiredParameterMissing
this.M3(1, 2.0); // MethodResolutionKind.BadArguments
this.M4(null, 2); // MethodResolutionKind.TypeInferenceFailed
this.M5<string, string>(null, 2); // MethodResolutionKind.BadGenericArity
this.M5<string, string>(null, 2); // Bad arity
this.M6(null, null); // Ambiguous
}
void M1(int x, int y) { }
......@@ -620,7 +620,7 @@ void N()
this.M2(1); // MethodResolutionKind.RequiredParameterMissing
this.M3(1, 2.0); // MethodResolutionKind.BadArguments
this.M4(null, 2); // MethodResolutionKind.TypeInferenceFailed
this.M5<string, string>(null, 2); // MethodResolutionKind.BadGenericArity
this.M5<string, string>(null, 2); // Bad arity
this.M6(null, null); // Ambiguous
}
}
......@@ -660,40 +660,40 @@ static class S
compilation.VerifyDiagnostics(
// (10,17): error CS1501: No overload for method 'M1' takes 3 arguments
// this.M1(1, 2, 3); // MethodResolutionKind.NoCorrespondingParameter
Diagnostic(ErrorCode.ERR_BadArgCount, "this.M1").WithArguments("M1", "3"),
// (11,17): error CS1501: No overload for method 'M2' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "this.M1").WithArguments("M1", "3").WithLocation(10, 17),
// (11,17): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'N1.N2.C.M2(int, int)'
// this.M2(1); // MethodResolutionKind.RequiredParameterMissing
Diagnostic(ErrorCode.ERR_BadArgCount, "this.M2").WithArguments("M2", "1"),
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "this.M2").WithArguments("y", "N1.N2.C.M2(int, int)").WithLocation(11, 17),
// (12,28): error CS1503: Argument 2: cannot convert from 'double' to 'int'
// this.M3(1, 2.0); // MethodResolutionKind.BadArguments
Diagnostic(ErrorCode.ERR_BadArgType, "2.0").WithArguments("2", "double", "int"),
Diagnostic(ErrorCode.ERR_BadArgType, "2.0").WithArguments("2", "double", "int").WithLocation(12, 28),
// (13,17): error CS0411: The type arguments for method 'N1.N2.C.M4<T>(T, int)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// this.M4(null, 2); // MethodResolutionKind.TypeInferenceFailed
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "this.M4").WithArguments("N1.N2.C.M4<T>(T, int)"),
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "this.M4").WithArguments("N1.N2.C.M4<T>(T, int)").WithLocation(13, 17),
// (14,22): error CS0305: Using the generic method 'N1.N2.C.M5<T>(T, int)' requires 1 type arguments
// this.M5<string, string>(null, 2); // MethodResolutionKind.BadGenericArity
Diagnostic(ErrorCode.ERR_BadArity, "M5<string, string>").WithArguments("N1.N2.C.M5<T>(T, int)", "method", "1"),
// this.M5<string, string>(null, 2); // Bad arity
Diagnostic(ErrorCode.ERR_BadArity, "M5<string, string>").WithArguments("N1.N2.C.M5<T>(T, int)", "method", "1").WithLocation(14, 22),
// (15,17): error CS0121: The call is ambiguous between the following methods or properties: 'N1.N2.C.M6(object, string)' and 'N1.N2.C.M6(string, object)'
// this.M6(null, null); // Ambiguous
Diagnostic(ErrorCode.ERR_AmbigCall, "this.M6").WithArguments("N1.N2.C.M6(object, string)", "N1.N2.C.M6(string, object)"),
Diagnostic(ErrorCode.ERR_AmbigCall, "this.M6").WithArguments("N1.N2.C.M6(object, string)", "N1.N2.C.M6(string, object)").WithLocation(15, 17),
// (41,17): error CS1501: No overload for method 'M1' takes 3 arguments
// this.M1(1, 2, 3); // MethodResolutionKind.NoCorrespondingParameter
Diagnostic(ErrorCode.ERR_BadArgCount, "this.M1").WithArguments("M1", "3"),
// (42,17): error CS1501: No overload for method 'M2' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "this.M1").WithArguments("M1", "3").WithLocation(41, 17),
// (42,17): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'N1.N2.C.M2(int, int)'
// this.M2(1); // MethodResolutionKind.RequiredParameterMissing
Diagnostic(ErrorCode.ERR_BadArgCount, "this.M2").WithArguments("M2", "1"),
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "this.M2").WithArguments("y", "N1.N2.C.M2(int, int)").WithLocation(42, 17),
// (43,28): error CS1503: Argument 2: cannot convert from 'double' to 'int'
// this.M3(1, 2.0); // MethodResolutionKind.BadArguments
Diagnostic(ErrorCode.ERR_BadArgType, "2.0").WithArguments("2", "double", "int"),
Diagnostic(ErrorCode.ERR_BadArgType, "2.0").WithArguments("2", "double", "int").WithLocation(43, 28),
// (44,17): error CS0411: The type arguments for method 'N1.N2.C.M4<T>(T, int)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// this.M4(null, 2); // MethodResolutionKind.TypeInferenceFailed
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "this.M4").WithArguments("N1.N2.C.M4<T>(T, int)"),
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "this.M4").WithArguments("N1.N2.C.M4<T>(T, int)").WithLocation(44, 17),
// (45,47): error CS1503: Argument 3: cannot convert from 'int' to 'string'
// this.M5<string, string>(null, 2); // MethodResolutionKind.BadGenericArity
Diagnostic(ErrorCode.ERR_BadArgType, "2").WithArguments("3", "int", "string"),
// this.M5<string, string>(null, 2); // Bad arity
Diagnostic(ErrorCode.ERR_BadArgType, "2").WithArguments("3", "int", "string").WithLocation(45, 47),
// (46,17): error CS0121: The call is ambiguous between the following methods or properties: 'N1.N2.C.M6(object, string)' and 'N1.N2.C.M6(string, object)'
// this.M6(null, null); // Ambiguous
Diagnostic(ErrorCode.ERR_AmbigCall, "this.M6").WithArguments("N1.N2.C.M6(object, string)", "N1.N2.C.M6(string, object)"));
Diagnostic(ErrorCode.ERR_AmbigCall, "this.M6").WithArguments("N1.N2.C.M6(object, string)", "N1.N2.C.M6(string, object)").WithLocation(46, 17));
}
/// <summary>
......@@ -2709,11 +2709,14 @@ static void M(this object x, object y)
}";
CreateCompilationWithMscorlibAndSystemCore(source).VerifyDiagnostics(
// (5,9): error CS1501: No overload for method 'M' takes 2 arguments
// x.M(x, y);
Diagnostic(ErrorCode.ERR_BadArgCount, "x.M").WithArguments("M", "2").WithLocation(5, 9),
// (6,9): error CS1501: No overload for method 'M' takes 0 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "x.M").WithArguments("M", "0").WithLocation(6, 9),
// (7,9): error CS1501: No overload for method 'M' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "1").WithLocation(7, 9));
// (6,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'S.M(object, object)'
// x.M();
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "x.M").WithArguments("y", "S.M(object, object)").WithLocation(6, 9),
// (7,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'S.M(object, object)'
// M(x);
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "M").WithArguments("y", "S.M(object, object)").WithLocation(7, 9));
}
[WorkItem(543711)]
......
......@@ -1546,8 +1546,9 @@ static void M(B b)
}";
var compilation2 = CreateCompilationWithMscorlib(source2, new[] { reference1 });
compilation2.VerifyDiagnostics(
// (5,17): error CS1501: No overload for method 'Q' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "b.Q[0]").WithArguments("Q", "1").WithLocation(5, 17));
// (5,17): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'B.Q[object, object]'
// var o = b.Q[0];
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "b.Q[0]").WithArguments("y", "B.Q[object, object]").WithLocation(5, 17));
var source3 =
@"class C
{
......
......@@ -234,12 +234,12 @@ int F(C c)
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (9,16): error CS1501: No overload for method 'this' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "this[0]").WithArguments("this", "1"),
// (9,16): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'C.this[int, int]'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "this[0]").WithArguments("y", "C.this[int, int]").WithLocation(9, 16),
// (10,18): error CS1503: Argument 2: cannot convert from 'C' to 'int'
Diagnostic(ErrorCode.ERR_BadArgType, "c").WithArguments("2", "C", "int"),
Diagnostic(ErrorCode.ERR_BadArgType, "c").WithArguments("2", "C", "int").WithLocation(10, 18),
// (11,13): error CS1501: No overload for method 'this' takes 3 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "c[1, 2, 3]").WithArguments("this", "3"));
Diagnostic(ErrorCode.ERR_BadArgCount, "c[1, 2, 3]").WithArguments("this", "3").WithLocation(11, 13));
}
[Fact]
......@@ -835,8 +835,8 @@ void M(C c)
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (7,9): error CS1501: No overload for method 'this' takes 1 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "c[0]").WithArguments("this", "1"),
// (7,9): error CS7036: There is no argument given that corresponds to the required formal parameter 'y' of 'C.this[int, long]'
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "c[0]").WithArguments("y", "C.this[int, long]"),
// (7,16): error CS1501: No overload for method 'this' takes 3 arguments
Diagnostic(ErrorCode.ERR_BadArgCount, "c[0, 0, 0]").WithArguments("this", "3"),
// (8,11): error CS1503: Argument 1: cannot convert from 'bool' to 'int'
......
......@@ -10771,9 +10771,14 @@ public static void Main()
}
}
";
var comp = DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text,
new ErrorDescription { Code = (int)ErrorCode.ERR_DuplicateNamedAttributeArgument, Line = 2, Column = 39 },
new ErrorDescription { Code = (int)ErrorCode.ERR_BadCtorArgCount, Line = 2, Column = 2 });
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (2,39): error CS0643: 'AllowMultiple' duplicate named attribute argument
// [AttributeUsage(AllowMultiple = true, AllowMultiple = false)]
Diagnostic(ErrorCode.ERR_DuplicateNamedAttributeArgument, "AllowMultiple = false").WithArguments("AllowMultiple").WithLocation(2, 39),
// (2,2): error CS7036: There is no argument given that corresponds to the required formal parameter 'validOn' of 'System.AttributeUsageAttribute.AttributeUsageAttribute(System.AttributeTargets)'
// [AttributeUsage(AllowMultiple = true, AllowMultiple = false)]
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "AttributeUsage(AllowMultiple = true, AllowMultiple = false)").WithArguments("validOn", "System.AttributeUsageAttribute.AttributeUsageAttribute(System.AttributeTargets)").WithLocation(2, 2));
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册