[mcs] Throw expression cannot be placed after any colon.
authorMarek Safar <marek.safar@gmail.com>
Mon, 5 Jun 2017 13:27:28 +0000 (15:27 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 5 Jun 2017 13:27:28 +0000 (15:27 +0200)
mcs/mcs/cs-parser.jay
mcs/mcs/cs-tokenizer.cs
mcs/tests/test-946.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 153a6bc7bdba4d8cc56dca48f8c9396ed3e00df3..8d36abae8dc257b8943945bc0cb39a42aa6f76a4 100644 (file)
@@ -4852,6 +4852,15 @@ conditional_expression
                $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
                lbag.AddLocation ($$, GetLocation ($4));
          }
+       | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
+         {
+               if (lang_version < LanguageVersion.V_7)
+                       FeatureIsNotAvailable (lexer.Location, "throw expression");
+
+               var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
+               $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
+               lbag.AddLocation ($$, GetLocation ($4));
+         }
        | null_coalescing_expression INTERR expression error
          {
                Error_SyntaxError (yyToken);
index afa69c86a4bc307d083b9c8b0b9373a178ff2aa8..505173cb4f9e10a70e72432bae7cd9e4bcf323b3 100644 (file)
@@ -899,7 +899,6 @@ namespace Mono.CSharp
                                case Token.ARROW:
                                case Token.OP_COALESCING:
                                case Token.INTERR:
-                               case Token.COLON:
                                        res = Token.THROW_EXPR;
                                        break;
                                }
diff --git a/mcs/tests/test-946.cs b/mcs/tests/test-946.cs
new file mode 100644 (file)
index 0000000..8841f1b
--- /dev/null
@@ -0,0 +1,19 @@
+using System;
+
+class X
+{
+       public static void Main ()
+       {
+
+       }
+
+       int ImportScope (int scope)
+       {
+               switch (scope) {
+               case 200:
+                       throw new NotImplementedException ();
+               }
+
+               throw new NotSupportedException ();
+       }       
+}
\ No newline at end of file
index e2d36914506db3fb8b76725266fe3dda9e7a8412..a3ef14c10096330b3344d73ec50948f93759d401 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-946.cs">
+    <type name="X">
+      <method name="Void Main()" attrs="150">
+        <size>2</size>
+      </method>
+      <method name="Int32 ImportScope(Int32)" attrs="129">
+        <size>29</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-95.cs">
     <type name="X">
       <method name="Int32 Main()" attrs="150">