[mcs] Better check for invalid attribute targets. Fixes #17447
authorMarek Safar <marek.safar@gmail.com>
Tue, 28 Jan 2014 09:16:12 +0000 (10:16 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 28 Jan 2014 09:16:58 +0000 (10:16 +0100)
mcs/errors/cs0658-4.cs [deleted file]
mcs/errors/cs1525-55.cs [new file with mode: 0644]
mcs/mcs/cs-parser.jay
mcs/tests/test-885.cs

diff --git a/mcs/errors/cs0658-4.cs b/mcs/errors/cs0658-4.cs
deleted file mode 100644 (file)
index 5073abc..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// CS0658: `)' is invalid attribute target. All attributes in this attribute section will be ignored
-// Line : 9
-// Compiler options: -warnaserror -warn:1
-
-namespace CompilerCrashWithAttributes
-{
-       public class Main
-       {
-               [MyAttribute1, MyAttribute1)]
-               public Main ()
-               {
-               }
-       }
-
-       public class MyAttribute1 : Attribute
-       {
-       }
-}
\ No newline at end of file
diff --git a/mcs/errors/cs1525-55.cs b/mcs/errors/cs1525-55.cs
new file mode 100644 (file)
index 0000000..94621fe
--- /dev/null
@@ -0,0 +1,17 @@
+// CS1525: Unexpected symbol `)', expecting `(', `,', `.', or `]'
+// Line: 8
+
+namespace CompilerCrashWithAttributes
+{
+       public class Main
+       {
+               [MyAttribute1, MyAttribute1)]
+               public Main ()
+               {
+               }
+       }
+
+       public class MyAttribute1 : Attribute
+       {
+       }
+}
\ No newline at end of file
index 901ce7d3f438db85375bd646dacd20a4612ed7b6..54cfde6ae2d8f842a4d1487c564ba37577e48bd3 100644 (file)
@@ -739,7 +739,7 @@ attribute_section_cont
          }
        | error
          {
-               CheckAttributeTarget (GetTokenName (yyToken), GetLocation ($1)); 
+               CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)); 
                $$ = null;
          }
        ;       
@@ -748,7 +748,7 @@ attribute_target
        : IDENTIFIER
          {
                var lt = (LocatedToken) $1;
-               $$ = CheckAttributeTarget (lt.Value, lt.Location);
+               $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
          }
        | EVENT  { $$ = "event"; }
        | RETURN { $$ = "return"; }
@@ -6980,15 +6980,20 @@ Location PopLocation ()
        return location_stack.Pop ();
 }
 
-string CheckAttributeTarget (string a, Location l)
+string CheckAttributeTarget (int token, string a, Location l)
 {
        switch (a) {
        case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
                        return a;
        }
 
-       report.Warning (658, 1, l,
-                "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
+       if (!Tokenizer.IsValidIdentifier (a)) {
+               Error_SyntaxError (token);
+       } else {
+               report.Warning (658, 1, l,
+                        "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
+       }
+
        return string.Empty;
 }
 
index 2bd071006069808c5f670b3372d744c7c0be05f3..5f6fc13d3d85a7c3a9fba057904ca066010d43a0 100644 (file)
@@ -12,7 +12,6 @@ class A : Attribute
        }
 }
 
-
 class C
 {
        [A (0.7f * 100.0f)]