Skip to content

Commit

Permalink
Fix Issue 4946 - Not good error message with wrongly positioned 'const'
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Nov 3, 2017
1 parent f344696 commit f9879d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ddmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -4766,7 +4766,14 @@ final class Parser(AST) : Lexer
}
else if (!f.frequire && !f.fensure) // allow these even with no body
{
error("semicolon expected following function declaration");
TOK t = token.value;
if (t == TOKconst || t == TOKimmutable || t == TOKinout || t == TOKreturn ||
t == TOKshared || t == TOKnothrow || t == TOKpure)
error("'%s' cannot be placed after a template constraint", token.toChars);
else if (t == TOKat)
error("attributes cannot be placed after a template constraint");
else
error("semicolon expected following function declaration");
}
break;
}
Expand Down
19 changes: 19 additions & 0 deletions test/fail_compilation/test4946.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* TEST_OUTPUT:
---
fail_compilation/test4946.d(13): Error: 'pure' cannot be placed after a template constraint
fail_compilation/test4946.d(14): Error: 'const' cannot be placed after a template constraint
fail_compilation/test4946.d(15): Error: 'immutable' cannot be placed after a template constraint
fail_compilation/test4946.d(16): Error: 'inout' cannot be placed after a template constraint
fail_compilation/test4946.d(17): Error: 'shared' cannot be placed after a template constraint
fail_compilation/test4946.d(18): Error: 'nothrow' cannot be placed after a template constraint
fail_compilation/test4946.d(19): Error: attributes cannot be placed after a template constraint
---
*/

void bar1(int x)() if (x > 0) pure { int a;}
void bar2(int x)() if (x > 0) const { int a;}
void bar3(int x)() if (x > 0) immutable { int a;}
void bar4(int x)() if (x > 0) inout { int a;}
void bar5(int x)() if (x > 0) shared { int a;}
void bar6(int x)() if (x > 0) nothrow { int a;}
void bar7(int x)() if (x > 0) @safe { int a;}

0 comments on commit f9879d7

Please sign in to comment.