From 2ca4575eeb0a6ac3235c4d382a3786e63864840f Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Mon, 5 Jun 2017 15:27:28 +0200 Subject: [PATCH] [mcs] Throw expression cannot be placed after any colon. --- mcs/mcs/cs-parser.jay | 9 +++++++++ mcs/mcs/cs-tokenizer.cs | 1 - mcs/tests/test-946.cs | 19 +++++++++++++++++++ mcs/tests/ver-il-net_4_x.xml | 13 +++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 mcs/tests/test-946.cs diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index 153a6bc7bdb..8d36abae8dc 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -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); diff --git a/mcs/mcs/cs-tokenizer.cs b/mcs/mcs/cs-tokenizer.cs index afa69c86a4b..505173cb4f9 100644 --- a/mcs/mcs/cs-tokenizer.cs +++ b/mcs/mcs/cs-tokenizer.cs @@ -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 index 00000000000..8841f1b8293 --- /dev/null +++ b/mcs/tests/test-946.cs @@ -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 diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index e2d36914506..a3ef14c1009 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -52754,6 +52754,19 @@ + + + + 2 + + + 29 + + + 7 + + + -- 2.25.1