From d01a82be09e7f98ae960658ce61e863b90101625 Mon Sep 17 00:00:00 2001 From: 0xEAB Date: Wed, 5 Sep 2018 19:18:58 +0200 Subject: [PATCH] Fix issue 19225 - Confusing error message on `static else` So users assuming `static else` is fine get a helpful error message. --- src/dmd/parse.d | 4 +++- test/fail_compilation/diag19225.d | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/fail_compilation/diag19225.d diff --git a/src/dmd/parse.d b/src/dmd/parse.d index bff1394ff725..76936616d9b3 100644 --- a/src/dmd/parse.d +++ b/src/dmd/parse.d @@ -3686,6 +3686,8 @@ final class Parser(AST) : Lexer default: error("basic type expected, not `%s`", token.toChars()); + if (token.value == TOK.else_) + errorSupplemental(token.loc, "There's no `static else`, use `else` instead."); t = AST.Type.terror; break; } @@ -4558,7 +4560,7 @@ final class Parser(AST) : Lexer bool isThis = (t.ty == AST.Tident && (cast(AST.TypeIdentifier)t).ident == Id.This && token.value == TOK.assign); if (ident) checkCstyleTypeSyntax(loc, t, alt, ident); - else if (!isThis) + else if (!isThis && (t != AST.Type.terror)) error("no identifier for declarator `%s`", t.toChars()); if (tok == TOK.alias_) diff --git a/test/fail_compilation/diag19225.d b/test/fail_compilation/diag19225.d new file mode 100644 index 000000000000..bbb825159f26 --- /dev/null +++ b/test/fail_compilation/diag19225.d @@ -0,0 +1,15 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/diag19225.d(14): Error: basic type expected, not `else` +fail_compilation/diag19225.d(14): There's no `static else`, use `else` instead. +fail_compilation/diag19225.d(14): Error: found `else` without a corresponding `if`, `version` or `debug` statement +fail_compilation/diag19225.d(15): Error: unrecognized declaration +--- +*/ + +void main() +{ + static if (true) {} + static else {} +}