Skip to content

Commit

Permalink
Fix issue 19225 - Confusing error message on static else
Browse files Browse the repository at this point in the history
So users assuming `static else` is fine get a helpful error message.
  • Loading branch information
0xEAB committed Sep 6, 2018
1 parent 8bdf59d commit d01a82b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dmd/parse.d
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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_)
Expand Down
15 changes: 15 additions & 0 deletions 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 {}
}

0 comments on commit d01a82b

Please sign in to comment.