From ae2b6e58a8bc82c06962e65c17c22b933599b0e7 Mon Sep 17 00:00:00 2001 From: leppie Date: Fri, 20 Nov 2015 11:49:40 +0200 Subject: [PATCH] Implements #6061 --- .../Portable/CSharpResources.Designer.cs | 2 +- .../CSharp/Portable/CSharpResources.resx | 4 +- .../Portable/Symbols/Symbol_Attributes.cs | 7 +- .../Attributes/AttributeTests_Locations.cs | 120 +++++++++--------- 4 files changed, 67 insertions(+), 66 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs index 90173443b07..6e734625069 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs +++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs @@ -11711,7 +11711,7 @@ internal class CSharpResources { } /// - /// Looks up a localized string similar to '{0}' is not a recognized attribute location. All attributes in this block will be ignored.. + /// Looks up a localized string similar to '{0}' is not a recognized attribute location. Valid attribute locations for this declaration are '{1}'. All attributes in this block will be ignored.. /// internal static string WRN_InvalidAttributeLocation { get { diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 6eb512de9e3..26d1c38cac7 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -1758,7 +1758,7 @@ If such a class is used as a base class and if the deriving class defines a dest Not a valid attribute location for this declaration - '{0}' is not a recognized attribute location. All attributes in this block will be ignored. + '{0}' is not a recognized attribute location. Valid attribute locations for this declaration are '{1}'. All attributes in this block will be ignored. Not a recognized attribute location @@ -4666,4 +4666,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Public signing was specified and requires a public key, but no public key was specified. - + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs b/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs index 554da91a5b6..a7397bac844 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs @@ -462,6 +462,8 @@ private static bool MatchAttributeTarget(IAttributeTargetSymbol attributeTarget, return isOwner; } + AttributeLocation allowedTargets = attributesOwner.AllowedAttributeLocations; + AttributeLocation explicitTarget = targetOpt.GetAttributeLocation(); if (explicitTarget == AttributeLocation.None) { @@ -470,13 +472,12 @@ private static bool MatchAttributeTarget(IAttributeTargetSymbol attributeTarget, { //NOTE: ValueText so that we accept targets like "@return", to match dev10 (DevDiv #2591). diagnostics.Add(ErrorCode.WRN_InvalidAttributeLocation, - targetOpt.Identifier.GetLocation(), targetOpt.Identifier.ValueText); + targetOpt.Identifier.GetLocation(), targetOpt.Identifier.ValueText, allowedTargets.ToDisplayString()); } return false; } - - AttributeLocation allowedTargets = attributesOwner.AllowedAttributeLocations; + if ((explicitTarget & allowedTargets) == 0) { // error: invalid target for symbol diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Locations.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Locations.cs index 96bcf925c2a..38e29f7bc5c 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Locations.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Locations.cs @@ -114,8 +114,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "type"), // (17,2): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "type"), - // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "type")); } [Fact] @@ -162,8 +162,8 @@ struct S Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "type"), // (17,2): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "type"), - // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "type")); } [Fact] @@ -210,8 +210,8 @@ enum E Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "type"), // (17,2): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "type"), - // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "type")); } [Fact] @@ -258,8 +258,8 @@ interface I Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "type"), // (17,2): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "type"), - // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "type")); } [Fact] @@ -302,8 +302,8 @@ public class A : Attribute { } Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "type, return"), // (17,2): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'type, return'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "type, return"), - // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (18,2): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'type, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "type, return")); } [Fact] @@ -349,8 +349,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "method, return"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, return'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, return"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, return")); } [Fact] @@ -398,8 +398,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "field"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'field'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "field"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate"), + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. AValid attribute locations for this declaration are 'field'. ll attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "field"), // (21,9): warning CS0169: The field 'C.a' is never used Diagnostic(ErrorCode.WRN_UnreferencedField, "a").WithArguments("C.a")); } @@ -449,8 +449,8 @@ enum E Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "field"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'field'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "field"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'field'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "field")); } [Fact] @@ -498,8 +498,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "property"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'property'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "property"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'property'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "property")); } [Fact] @@ -550,8 +550,8 @@ int Foo Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "method, return"), // (21,10): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, return'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, return"), - // (22,10): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (22,10): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, return")); } [Fact] @@ -600,8 +600,8 @@ int Foo Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "event").WithArguments("event", "method, param, return"), // (23,10): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, param, return'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, param, return"), - // (24,10): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (24,10): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, param, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, param, return")); } [Fact] @@ -645,8 +645,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "method, field, event"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, field, event'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, field, event"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate"), + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, field, event'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, field, event"), // (21,25): warning CS0067: The event 'C.e' is never used Diagnostic(ErrorCode.WRN_UnreferencedEvent, "e").WithArguments("C.e")); } @@ -694,8 +694,8 @@ interface I Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "method, event"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, event'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, event"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, event'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, event")); } [Fact] @@ -743,8 +743,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "event"), // (19,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'event'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "event"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'event'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "event")); } [Fact] @@ -793,8 +793,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "event").WithArguments("event", "method, param, return"), // (21,10): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, param, return'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, param, return"), - // (22,10): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (22,10): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, param, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, param, return")); } [Fact] @@ -843,8 +843,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "event").WithArguments("event", "method, param, return"), // (23,10): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'method, param, return'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "method, param, return"), - // (24,10): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (24,10): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, param, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "method, param, return")); } [Fact] @@ -894,8 +894,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "return").WithArguments("return", "typevar"), // (18,6): warning CS0657: 'param' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'typevar'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "param").WithArguments("param", "typevar"), - // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (20,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'typevar'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "typevar")); } [Fact] @@ -945,8 +945,8 @@ int x Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "return").WithArguments("return", "param"), // (20,10): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "param"), - // (21,10): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (21,10): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "param")); } [Fact] @@ -993,8 +993,8 @@ int x Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "return").WithArguments("return", "param"), // (18,6): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "param"), - // (19,6): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (19,6): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "param")); } [Fact] @@ -1047,8 +1047,8 @@ class C Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "return").WithArguments("return", "param"), // (20,10): warning CS0657: 'typevar' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "typevar").WithArguments("typevar", "param"), - // (21,10): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate")); + // (21,10): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "param")); } [Fact] @@ -1073,24 +1073,24 @@ class C { }"; CreateCompilationWithMscorlib(source).VerifyDiagnostics( - // (7,2): warning CS0658: 'class' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "class").WithArguments("class"), - // (8,2): warning CS0658: 'struct' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "struct").WithArguments("struct"), - // (9,2): warning CS0658: 'interface' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "interface").WithArguments("interface"), - // (10,2): warning CS0658: 'delegate' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate"), - // (11,2): warning CS0658: 'enum' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "enum").WithArguments("enum"), - // (12,2): warning CS0658: 'add' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "add").WithArguments("add"), - // (13,2): warning CS0658: 'remove' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "remove").WithArguments("remove"), - // (14,2): warning CS0658: 'get' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "get").WithArguments("get"), - // (15,2): warning CS0658: 'set' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "set").WithArguments("set")); + // (7,2): warning CS0658: 'class' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "class").WithArguments("class", "type"), + // (8,2): warning CS0658: 'struct' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "struct").WithArguments("struct", "type"), + // (9,2): warning CS0658: 'interface' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "interface").WithArguments("interface", "type"), + // (10,2): warning CS0658: 'delegate' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "delegate").WithArguments("delegate", "type"), + // (11,2): warning CS0658: 'enum' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "enum").WithArguments("enum", "type"), + // (12,2): warning CS0658: 'add' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "add").WithArguments("add", "type"), + // (13,2): warning CS0658: 'remove' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "remove").WithArguments("remove", "type"), + // (14,2): warning CS0658: 'get' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "get").WithArguments("get", "type"), + // (15,2): warning CS0658: 'set' is not a recognized attribute location. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "set").WithArguments("set", "type")); } [Fact, WorkItem(545555, "DevDiv")] @@ -1120,8 +1120,8 @@ public class A : Attribute { } "; CompileAndVerify(source, expectedOutput: "Attribute Count=1").VerifyDiagnostics( - // (12,6): warning CS0658: 'foo' is not a recognized attribute location. All attributes in this block will be ignored. - Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "foo").WithArguments("foo")); + // (12,6): warning CS0658: 'foo' is not a recognized attribute location. Valid attribute locations for this declaration are 'method, return'. All attributes in this block will be ignored. + Diagnostic(ErrorCode.WRN_InvalidAttributeLocation, "foo").WithArguments("foo", "method, return")); } [WorkItem(537613, "DevDiv"), WorkItem(537738, "DevDiv")] -- GitLab