Bug 8684 – Missing ')' in argument list creates a sea of error messages

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-18T00:46:40Z
Last change time
2019-11-04T20:29:46Z
Keywords
bootcamp, diagnostic, pull
Assigned to
No Owner
Creator
Don

Comments

Comment #0 by clugdbug — 2012-09-18T00:46:40Z
int foo(int n, int m) { int x = foo( 5, m; for (int q=0; q<10; ++q){ ++q; } return 2; } The error is a single missing ')'. But the compiler spits an error for each extra token in the file. Probably, as soon as it hits an unexpected ;, it should assume that it has reached the end of the argument list. In reality this situation often happens in situations where the last parameter is a function call, and parentheses are mismatched: foo(5, foo(3, foo(7,6)); ---------- r.d(4): Error: found ';' when expecting ',' following argument r.d(5): Error: expression expected, not 'for' r.d(5): Error: found 'q' when expecting '.' following int r.d(5): Error: found '=' when expecting identifier following 'int.' r.d(5): Error: found '0' when expecting ',' following argument r.d(5): Error: expression expected, not ';' r.d(5): Error: found 'q' when expecting ',' following argument r.d(5): Error: expression expected, not '<' r.d(5): Error: found '10' when expecting ',' following argument r.d(5): Error: expression expected, not ';' r.d(5): Error: found 'q' when expecting ',' following argument r.d(5): Error: expression expected, not ')' r.d(5): Error: found '{' when expecting ',' following argument r.d(6): Error: found ';' when expecting ',' following argument r.d(7): Error: expression expected, not '}' r.d(8): Error: found 'return' when expecting ',' following argument r.d(8): Error: found ';' when expecting ',' following argument r.d(9): Error: expression expected, not '}' r.d(12): Error: found 'EOF' when expecting ',' following argument r.d(12): Error: found 'EOF' when expecting ')' following argument list
Comment #1 by bearophile_hugs — 2012-10-12T14:31:38Z
Some cases that look related (but I don't know if they are actually similar). From the thread: http://forum.dlang.org/thread/[email protected] In the following examples I'd like the D compiler to give more focused error messages. ---------------------- int main() { for (int i = 0, i < 10, i++) { // do something } return 0; } temp.d(2): Error: semicolon expected, not '<' temp.d(2): Error: expression expected, not '<' temp.d(2): Error: found '10' when expecting ';' following for condition temp.d(2): Error: expression expected, not ',' temp.d(2): Error: found 'i' when expecting ')' temp.d(2): Error: expression expected, not ')' temp.d(2): Error: found '{' when expecting ';' following statement temp.d(5): Error: Declaration expected, not 'return' temp.d(6): Error: unrecognized declaration ---------------------- void main() { foreach (i, 0 .. 10) {} } temp.d(2): Error: basic type expected, not 0 temp.d(2): Error: no identifier for declarator int temp.d(2): Error: found '0' when expecting ';' temp.d(2): Error: expression expected, not '..' temp.d(2): Error: found '10' when expecting ')' temp.d(2): Error: found ')' instead of statement temp.d(3): Error: unrecognized declaration --------------------------------- void main() { int[10] data; foreach (i, x, data) {} } temp.d(3): Error: no identifier for declarator data temp.d(3): Error: found ')' when expecting ';' temp.d(4): Error: found '}' when expecting ')' temp.d(4): Error: found 'EOF' instead of statement temp.d(4): Error: found 'EOF' when expecting '}' following compound statement --------------------------------- void main() { int[10] data; foreach (i; x; data) {} } temp.d(3): Error: found ';' when expecting ')' temp.d(3): Error: found ')' when expecting ';' following statement ---------------------------------
Comment #2 by bearophile_hugs — 2012-10-12T14:32:31Z
--------------------------------- void main() { int value = 0; while (value < 10) do { // do something value++; } } temp.d(8): Error: found '}' when expecting 'while' temp.d(8): Error: found 'EOF' when expecting '(' temp.d(8): Error: expression expected, not 'EOF' temp.d(8): Error: found 'EOF' when expecting ')' temp.d(8): Deprecation: do-while statement without terminating ; is deprecated temp.d(8): Error: found 'EOF' when expecting '}' following compound statement ---------------------------------
Comment #3 by dlang-bot — 2019-11-01T21:42:36Z
@benjones updated dlang/dmd pull request #10529 "fix issue_8684 by bailing early in parseArguments" fixing this issue: - fix issue 8684 by bailing early in parseArguments https://github.com/dlang/dmd/pull/10529
Comment #4 by dlang-bot — 2019-11-04T20:29:46Z
dlang/dmd pull request #10529 "fix issue_8684 by bailing early in parseArguments" was merged into master: - be9114f791d499c09b29f532f47707521008df76 by Ben Jones: fix issue 8684 by bailing early in parseArguments added test example, simplified logic per @rainers suggestion https://github.com/dlang/dmd/pull/10529