Skip to content

Commit

Permalink
fix issue 8684 by bailing early in parseArguments
Browse files Browse the repository at this point in the history
added test example, simplified logic per @rainers suggestion
  • Loading branch information
benjones committed Nov 4, 2019
1 parent 4f42c58 commit be9114f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -8913,20 +8913,22 @@ final class Parser(AST) : Lexer
{
// function call
AST.Expressions* arguments;
TOK endtok;

arguments = new AST.Expressions();
endtok = token.value == TOK.leftBracket ? TOK.rightBracket : TOK.rightParentheses;
const endtok = token.value == TOK.leftBracket ? TOK.rightBracket : TOK.rightParentheses;

nextToken();

while (token.value != endtok && token.value != TOK.endOfFile)
{
auto arg = parseAssignExp();
arguments.push(arg);
if (token.value == endtok)
if (token.value != TOK.comma)
break;
check(TOK.comma);

nextToken(); //comma
}

check(endtok);

return arguments;
Expand Down
16 changes: 16 additions & 0 deletions test/fail_compilation/diag8684.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag8684.d(11): Error: found `;` when expecting `)`
fail_compilation/diag8684.d(12): Error: semicolon expected, not `for`
---
*/

int foo(int n, int m)
{
int x = foo( 5, m;
for (int q=0; q<10; ++q){
++q;
}
return 2;
}
19 changes: 7 additions & 12 deletions test/fail_compilation/ice11967.d
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice11967.d(18): Error: use `@(attributes)` instead of `[attributes]`
fail_compilation/ice11967.d(18): Error: expression expected, not `%`
fail_compilation/ice11967.d(18): Error: found `g` when expecting `,`
fail_compilation/ice11967.d(19): Error: @identifier or @(ArgumentList) expected, not `@End of File`
fail_compilation/ice11967.d(19): Error: valid attributes are `@property`, `@safe`, `@trusted`, `@system`, `@disable`, `@nogc`
fail_compilation/ice11967.d(19): Error: basic type expected, not `End of File`
fail_compilation/ice11967.d(19): Error: found `End of File` when expecting `}` following compound statement
fail_compilation/ice11967.d(19): Error: found `End of File` when expecting `,`
fail_compilation/ice11967.d(19): Error: found `End of File` when expecting `)`
fail_compilation/ice11967.d(19): Error: found `End of File` when expecting `,`
fail_compilation/ice11967.d(19): Error: found `End of File` when expecting `]`
fail_compilation/ice11967.d(19): Error: declaration expected following attribute, not end of file
fail_compilation/ice11967.d(13): Error: use `@(attributes)` instead of `[attributes]`
fail_compilation/ice11967.d(13): Error: expression expected, not `%`
fail_compilation/ice11967.d(13): Error: found `g` when expecting `)`
fail_compilation/ice11967.d(13): Error: found `{` when expecting `]`
fail_compilation/ice11967.d(14): Error: @identifier or @(ArgumentList) expected, not `@End of File`
fail_compilation/ice11967.d(14): Error: valid attributes are `@property`, `@safe`, `@trusted`, `@system`, `@disable`, `@nogc`
fail_compilation/ice11967.d(14): Error: declaration expected following attribute, not end of file
---
*/
[F(%g{@

0 comments on commit be9114f

Please sign in to comment.