diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index 8c0a1b13c9..eeaef8d7d8 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -1155,6 +1155,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer case TOK.leftCurly: { + const lcLoc = token.loc; const lookingForElseSave = lookingForElse; lookingForElse = Loc(); @@ -1164,6 +1165,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer { /* { */ error("matching `}` expected, not `%s`", token.toChars()); + eSink.errorSupplemental(lcLoc, "unmatched `{`"); } else nextToken(); @@ -6015,6 +6017,7 @@ LagainStc: } case TOK.leftCurly: { + const lcLoc = token.loc; const lookingForElseSave = lookingForElse; lookingForElse = Loc.initial; @@ -6037,7 +6040,14 @@ LagainStc: s = new AST.CompoundStatement(loc, statements); if (flags & (ParseStatementFlags.scope_ | ParseStatementFlags.curlyScope)) s = new AST.ScopeStatement(loc, s, token.loc); - check(TOK.rightCurly, "compound statement"); + if (token.value != TOK.rightCurly) + { + error(token.loc, "matching `}` expected following compound statement, not `%s`", + token.toChars()); + eSink.errorSupplemental(lcLoc, "unmatched `{`"); + } + else + nextToken(); lookingForElse = lookingForElseSave; break; } diff --git a/compiler/test/fail_compilation/e15876_1.d b/compiler/test/fail_compilation/e15876_1.d index 92e07342d4..0152cdee27 100644 --- a/compiler/test/fail_compilation/e15876_1.d +++ b/compiler/test/fail_compilation/e15876_1.d @@ -1,12 +1,13 @@ /* TEST_OUTPUT: --- -fail_compilation/e15876_1.d(16): Error: valid scope identifiers are `exit`, `failure`, or `success`, not `x` -fail_compilation/e15876_1.d(17): Error: found `End of File` when expecting `)` -fail_compilation/e15876_1.d(17): Error: found `End of File` instead of statement -fail_compilation/e15876_1.d(17): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/e15876_1.d(17): Error: found `End of File` when expecting `]` -fail_compilation/e15876_1.d(17): Error: no identifier for declarator `o[() +fail_compilation/e15876_1.d(17): Error: valid scope identifiers are `exit`, `failure`, or `success`, not `x` +fail_compilation/e15876_1.d(18): Error: found `End of File` when expecting `)` +fail_compilation/e15876_1.d(18): Error: found `End of File` instead of statement +fail_compilation/e15876_1.d(18): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/e15876_1.d(17): unmatched `{` +fail_compilation/e15876_1.d(18): Error: found `End of File` when expecting `]` +fail_compilation/e15876_1.d(18): Error: no identifier for declarator `o[() { scope(exit) __error__ } diff --git a/compiler/test/fail_compilation/e15876_2.d b/compiler/test/fail_compilation/e15876_2.d index 10ff7d53a9..92164a4fd8 100644 --- a/compiler/test/fail_compilation/e15876_2.d +++ b/compiler/test/fail_compilation/e15876_2.d @@ -1,10 +1,11 @@ /* TEST_OUTPUT: --- -fail_compilation/e15876_2.d(15): Error: identifier expected following `template` -fail_compilation/e15876_2.d(15): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/e15876_2.d(15): Error: found `End of File` when expecting `]` -fail_compilation/e15876_2.d(15): Error: no identifier for declarator `o[() +fail_compilation/e15876_2.d(16): Error: identifier expected following `template` +fail_compilation/e15876_2.d(16): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/e15876_2.d(15): unmatched `{` +fail_compilation/e15876_2.d(16): Error: found `End of File` when expecting `]` +fail_compilation/e15876_2.d(16): Error: no identifier for declarator `o[() { ; } diff --git a/compiler/test/fail_compilation/e15876_3.d b/compiler/test/fail_compilation/e15876_3.d index 0ac7229663..0482e87a54 100644 --- a/compiler/test/fail_compilation/e15876_3.d +++ b/compiler/test/fail_compilation/e15876_3.d @@ -1,18 +1,19 @@ /* TEST_OUTPUT: --- -fail_compilation/e15876_3.d(27): Error: unexpected `(` in declarator -fail_compilation/e15876_3.d(27): Error: basic type expected, not `=` -fail_compilation/e15876_3.d(28): Error: found `End of File` when expecting `(` -fail_compilation/e15876_3.d(28): Error: found `End of File` instead of statement -fail_compilation/e15876_3.d(28): Error: expression expected, not `End of File` -fail_compilation/e15876_3.d(28): Error: found `End of File` when expecting `;` following `for` condition -fail_compilation/e15876_3.d(28): Error: expression expected, not `End of File` -fail_compilation/e15876_3.d(28): Error: found `End of File` when expecting `)` -fail_compilation/e15876_3.d(28): Error: found `End of File` instead of statement -fail_compilation/e15876_3.d(28): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/e15876_3.d(28): Error: found `End of File` when expecting `)` -fail_compilation/e15876_3.d(28): Error: no identifier for declarator `d(_error_ = () +fail_compilation/e15876_3.d(28): Error: unexpected `(` in declarator +fail_compilation/e15876_3.d(28): Error: basic type expected, not `=` +fail_compilation/e15876_3.d(29): Error: found `End of File` when expecting `(` +fail_compilation/e15876_3.d(29): Error: found `End of File` instead of statement +fail_compilation/e15876_3.d(29): Error: expression expected, not `End of File` +fail_compilation/e15876_3.d(29): Error: found `End of File` when expecting `;` following `for` condition +fail_compilation/e15876_3.d(29): Error: expression expected, not `End of File` +fail_compilation/e15876_3.d(29): Error: found `End of File` when expecting `)` +fail_compilation/e15876_3.d(29): Error: found `End of File` instead of statement +fail_compilation/e15876_3.d(29): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/e15876_3.d(28): unmatched `{` +fail_compilation/e15876_3.d(29): Error: found `End of File` when expecting `)` +fail_compilation/e15876_3.d(29): Error: no identifier for declarator `d(_error_ = () { for (__error__ 0; 0) @@ -21,7 +22,7 @@ __error__ } } )` -fail_compilation/e15876_3.d(28): Error: semicolon expected following function declaration, not `End of File` +fail_compilation/e15876_3.d(29): Error: semicolon expected following function declaration, not `End of File` --- */ d(={for diff --git a/compiler/test/fail_compilation/e15876_4.d b/compiler/test/fail_compilation/e15876_4.d index f4bd407b9c..e5c3bbf567 100644 --- a/compiler/test/fail_compilation/e15876_4.d +++ b/compiler/test/fail_compilation/e15876_4.d @@ -1,17 +1,18 @@ /* TEST_OUTPUT: --- -fail_compilation/e15876_4.d(25): Error: found `)` when expecting `(` -fail_compilation/e15876_4.d(26): Error: found `End of File` when expecting `(` -fail_compilation/e15876_4.d(26): Error: found `End of File` instead of statement -fail_compilation/e15876_4.d(26): Error: expression expected, not `End of File` -fail_compilation/e15876_4.d(26): Error: found `End of File` when expecting `;` following `for` condition -fail_compilation/e15876_4.d(26): Error: expression expected, not `End of File` -fail_compilation/e15876_4.d(26): Error: found `End of File` when expecting `)` -fail_compilation/e15876_4.d(26): Error: found `End of File` instead of statement -fail_compilation/e15876_4.d(26): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/e15876_4.d(26): Error: found `End of File` when expecting `)` -fail_compilation/e15876_4.d(26): Error: no identifier for declarator `typeof(() +fail_compilation/e15876_4.d(26): Error: found `)` when expecting `(` +fail_compilation/e15876_4.d(27): Error: found `End of File` when expecting `(` +fail_compilation/e15876_4.d(27): Error: found `End of File` instead of statement +fail_compilation/e15876_4.d(27): Error: expression expected, not `End of File` +fail_compilation/e15876_4.d(27): Error: found `End of File` when expecting `;` following `for` condition +fail_compilation/e15876_4.d(27): Error: expression expected, not `End of File` +fail_compilation/e15876_4.d(27): Error: found `End of File` when expecting `)` +fail_compilation/e15876_4.d(27): Error: found `End of File` instead of statement +fail_compilation/e15876_4.d(27): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/e15876_4.d(26): unmatched `{` +fail_compilation/e15876_4.d(27): Error: found `End of File` when expecting `)` +fail_compilation/e15876_4.d(27): Error: no identifier for declarator `typeof(() { for (__error__ 0; 0) diff --git a/compiler/test/fail_compilation/e15876_5.d b/compiler/test/fail_compilation/e15876_5.d index 96b23e278c..6bebc29fcb 100644 --- a/compiler/test/fail_compilation/e15876_5.d +++ b/compiler/test/fail_compilation/e15876_5.d @@ -1,11 +1,12 @@ /* TEST_OUTPUT: --- -fail_compilation/e15876_5.d(16): Error: basic type expected, not `End of File` -fail_compilation/e15876_5.d(16): Error: semicolon expected to close `alias` declaration, not `End of File` -fail_compilation/e15876_5.d(16): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/e15876_5.d(16): Error: found `End of File` when expecting `]` -fail_compilation/e15876_5.d(16): Error: no identifier for declarator `p[() +fail_compilation/e15876_5.d(17): Error: basic type expected, not `End of File` +fail_compilation/e15876_5.d(17): Error: semicolon expected to close `alias` declaration, not `End of File` +fail_compilation/e15876_5.d(17): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/e15876_5.d(16): unmatched `{` +fail_compilation/e15876_5.d(17): Error: found `End of File` when expecting `]` +fail_compilation/e15876_5.d(17): Error: no identifier for declarator `p[() { alias ; } diff --git a/compiler/test/fail_compilation/fail196.d b/compiler/test/fail_compilation/fail196.d index 53505f496c..cdad5c491d 100644 --- a/compiler/test/fail_compilation/fail196.d +++ b/compiler/test/fail_compilation/fail196.d @@ -1,24 +1,26 @@ /* TEST_OUTPUT: --- -fail_compilation/fail196.d(27): Error: delimited string must end in `)"` -fail_compilation/fail196.d(27): Error: implicit string concatenation is error-prone and disallowed in D -fail_compilation/fail196.d(27): Use the explicit syntax instead (concatenating literals is `@nogc`): "foo(xxx)" ~ ";\n assert(s == " -fail_compilation/fail196.d(28): Error: semicolon needed to end declaration of `s`, instead of `foo` -fail_compilation/fail196.d(27): `s` declared here -fail_compilation/fail196.d(28): Error: found `");\n\n s = q"` when expecting `;` following statement `foo(xxx)` on line fail_compilation/fail196.d(28) -fail_compilation/fail196.d(30): Error: found `";\n assert(s == "` when expecting `;` following statement `[foo[xxx]]` on line fail_compilation/fail196.d(30) -fail_compilation/fail196.d(31): Error: found `");\n\n s = q"` when expecting `;` following statement `foo[xxx]` on line fail_compilation/fail196.d(31) -fail_compilation/fail196.d(33): Error: found `{` when expecting `;` following statement `foo` on line fail_compilation/fail196.d(33) -fail_compilation/fail196.d(33): Error: found `}` when expecting `;` following statement `xxx` on line fail_compilation/fail196.d(33) -fail_compilation/fail196.d(34): Error: found `foo` when expecting `;` following statement `";\n assert(s == "` on line fail_compilation/fail196.d(33) -fail_compilation/fail196.d(34): Error: found `}` when expecting `;` following statement `xxx` on line fail_compilation/fail196.d(34) -fail_compilation/fail196.d(36): Error: found `<` when expecting `;` following statement `");\n\n s = q" < foo` on line fail_compilation/fail196.d(34) -fail_compilation/fail196.d(37): Error: found `foo` when expecting `;` following statement `xxx >> ";\n assert(s == "` on line fail_compilation/fail196.d(36) -fail_compilation/fail196.d(37): Error: found `<` instead of statement -fail_compilation/fail196.d(43): Error: unterminated string constant starting at fail_compilation/fail196.d(43) -fail_compilation/fail196.d(45): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/fail196.d(45): Error: found `End of File` when expecting `}` following compound statement +fail_compilation/fail196.d(29): Error: delimited string must end in `)"` +fail_compilation/fail196.d(29): Error: implicit string concatenation is error-prone and disallowed in D +fail_compilation/fail196.d(29): Use the explicit syntax instead (concatenating literals is `@nogc`): "foo(xxx)" ~ ";\n assert(s == " +fail_compilation/fail196.d(30): Error: semicolon needed to end declaration of `s`, instead of `foo` +fail_compilation/fail196.d(29): `s` declared here +fail_compilation/fail196.d(30): Error: found `");\n\n s = q"` when expecting `;` following statement `foo(xxx)` on line fail_compilation/fail196.d(30) +fail_compilation/fail196.d(32): Error: found `";\n assert(s == "` when expecting `;` following statement `[foo[xxx]]` on line fail_compilation/fail196.d(32) +fail_compilation/fail196.d(33): Error: found `");\n\n s = q"` when expecting `;` following statement `foo[xxx]` on line fail_compilation/fail196.d(33) +fail_compilation/fail196.d(35): Error: found `{` when expecting `;` following statement `foo` on line fail_compilation/fail196.d(35) +fail_compilation/fail196.d(35): Error: found `}` when expecting `;` following statement `xxx` on line fail_compilation/fail196.d(35) +fail_compilation/fail196.d(36): Error: found `foo` when expecting `;` following statement `";\n assert(s == "` on line fail_compilation/fail196.d(35) +fail_compilation/fail196.d(36): Error: found `}` when expecting `;` following statement `xxx` on line fail_compilation/fail196.d(36) +fail_compilation/fail196.d(38): Error: found `<` when expecting `;` following statement `");\n\n s = q" < foo` on line fail_compilation/fail196.d(36) +fail_compilation/fail196.d(39): Error: found `foo` when expecting `;` following statement `xxx >> ";\n assert(s == "` on line fail_compilation/fail196.d(38) +fail_compilation/fail196.d(39): Error: found `<` instead of statement +fail_compilation/fail196.d(45): Error: unterminated string constant starting at fail_compilation/fail196.d(45) +fail_compilation/fail196.d(47): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/fail196.d(36): unmatched `{` +fail_compilation/fail196.d(47): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/fail196.d(28): unmatched `{` --- */ diff --git a/compiler/test/fail_compilation/fail315.d b/compiler/test/fail_compilation/fail315.d index c7fd78f8fc..1a7e0f35f9 100644 --- a/compiler/test/fail_compilation/fail315.d +++ b/compiler/test/fail_compilation/fail315.d @@ -1,13 +1,14 @@ /* TEST_OUTPUT: --- -fail_compilation/fail315.d-mixin-16(16): Error: found `;` when expecting `,` -fail_compilation/fail315.d-mixin-16(16): Error: expression expected, not `}` -fail_compilation/fail315.d-mixin-16(16): Error: found `End of File` when expecting `,` -fail_compilation/fail315.d-mixin-16(16): Error: found `End of File` when expecting `]` -fail_compilation/fail315.d-mixin-16(16): Error: found `End of File` when expecting `;` following `return` statement -fail_compilation/fail315.d-mixin-16(16): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/fail315.d(21): Error: template instance `fail315.foo!()` error instantiating +fail_compilation/fail315.d-mixin-17(17): Error: found `;` when expecting `,` +fail_compilation/fail315.d-mixin-17(17): Error: expression expected, not `}` +fail_compilation/fail315.d-mixin-17(17): Error: found `End of File` when expecting `,` +fail_compilation/fail315.d-mixin-17(17): Error: found `End of File` when expecting `]` +fail_compilation/fail315.d-mixin-17(17): Error: found `End of File` when expecting `;` following `return` statement +fail_compilation/fail315.d-mixin-17(17): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/fail315.d-mixin-17(17): unmatched `{` +fail_compilation/fail315.d(22): Error: template instance `fail315.foo!()` error instantiating --- */ diff --git a/compiler/test/fail_compilation/ice11965.d b/compiler/test/fail_compilation/ice11965.d index c8db60fe9c..9e6da3bbf8 100644 --- a/compiler/test/fail_compilation/ice11965.d +++ b/compiler/test/fail_compilation/ice11965.d @@ -1,10 +1,11 @@ /* TEST_OUTPUT: --- -fail_compilation/ice11965.d(15): Error: no identifier for declarator `b*` -fail_compilation/ice11965.d(15): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/ice11965.d(15): Error: found `End of File` when expecting `]` -fail_compilation/ice11965.d(15): Error: no identifier for declarator `u[() +fail_compilation/ice11965.d(16): Error: no identifier for declarator `b*` +fail_compilation/ice11965.d(16): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/ice11965.d(15): unmatched `{` +fail_compilation/ice11965.d(16): Error: found `End of File` when expecting `]` +fail_compilation/ice11965.d(16): Error: no identifier for declarator `u[() { b* A; } diff --git a/compiler/test/fail_compilation/ice11982.d b/compiler/test/fail_compilation/ice11982.d index 0f2ce413c4..0886df6167 100644 --- a/compiler/test/fail_compilation/ice11982.d +++ b/compiler/test/fail_compilation/ice11982.d @@ -1,19 +1,20 @@ /* TEST_OUTPUT: --- -fail_compilation/ice11982.d(19): Error: basic type expected, not `scope` -fail_compilation/ice11982.d(19): Error: found `scope` when expecting `;` following statement `new _error_` on line fail_compilation/ice11982.d(19) -fail_compilation/ice11982.d(19): Error: basic type expected, not `}` -fail_compilation/ice11982.d(19): Error: missing `{ ... }` for function literal -fail_compilation/ice11982.d(19): Error: C style cast illegal, use `cast(funk)function _error_() +fail_compilation/ice11982.d(20): Error: basic type expected, not `scope` +fail_compilation/ice11982.d(20): Error: found `scope` when expecting `;` following statement `new _error_` on line fail_compilation/ice11982.d(20) +fail_compilation/ice11982.d(20): Error: basic type expected, not `}` +fail_compilation/ice11982.d(20): Error: missing `{ ... }` for function literal +fail_compilation/ice11982.d(20): Error: C style cast illegal, use `cast(funk)function _error_() { } ` -fail_compilation/ice11982.d(19): Error: found `}` when expecting `;` following statement `cast(funk)function _error_() +fail_compilation/ice11982.d(20): Error: found `}` when expecting `;` following statement `cast(funk)function _error_() { } -` on line fail_compilation/ice11982.d(19) -fail_compilation/ice11982.d(20): Error: found `End of File` when expecting `}` following compound statement +` on line fail_compilation/ice11982.d(20) +fail_compilation/ice11982.d(21): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/ice11982.d(20): unmatched `{` --- */ void main() { new scope ( funk ) function } diff --git a/compiler/test/fail_compilation/ice15855.d b/compiler/test/fail_compilation/ice15855.d index b26fe4cda0..f7ad390068 100644 --- a/compiler/test/fail_compilation/ice15855.d +++ b/compiler/test/fail_compilation/ice15855.d @@ -2,16 +2,17 @@ /* TEST_OUTPUT: --- -fail_compilation/ice15855.d(27): Error: found `End of File` when expecting `(` -fail_compilation/ice15855.d(27): Error: found `End of File` instead of statement -fail_compilation/ice15855.d(27): Error: expression expected, not `End of File` -fail_compilation/ice15855.d(27): Error: found `End of File` when expecting `;` following `for` condition -fail_compilation/ice15855.d(27): Error: expression expected, not `End of File` -fail_compilation/ice15855.d(27): Error: found `End of File` when expecting `)` -fail_compilation/ice15855.d(27): Error: found `End of File` instead of statement -fail_compilation/ice15855.d(27): Error: found `End of File` when expecting `}` following compound statement -fail_compilation/ice15855.d(27): Error: found `End of File` when expecting `]` -fail_compilation/ice15855.d(27): Error: no identifier for declarator `a[() +fail_compilation/ice15855.d(28): Error: found `End of File` when expecting `(` +fail_compilation/ice15855.d(28): Error: found `End of File` instead of statement +fail_compilation/ice15855.d(28): Error: expression expected, not `End of File` +fail_compilation/ice15855.d(28): Error: found `End of File` when expecting `;` following `for` condition +fail_compilation/ice15855.d(28): Error: expression expected, not `End of File` +fail_compilation/ice15855.d(28): Error: found `End of File` when expecting `)` +fail_compilation/ice15855.d(28): Error: found `End of File` instead of statement +fail_compilation/ice15855.d(28): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/ice15855.d(27): unmatched `{` +fail_compilation/ice15855.d(28): Error: found `End of File` when expecting `]` +fail_compilation/ice15855.d(28): Error: no identifier for declarator `a[() { for (__error__ 0; 0) diff --git a/compiler/test/fail_compilation/misc_parser_err_cov1.d b/compiler/test/fail_compilation/misc_parser_err_cov1.d index d136144092..a719b123a6 100644 --- a/compiler/test/fail_compilation/misc_parser_err_cov1.d +++ b/compiler/test/fail_compilation/misc_parser_err_cov1.d @@ -24,7 +24,8 @@ fail_compilation/misc_parser_err_cov1.d(40): Error: identifier or `new` expected fail_compilation/misc_parser_err_cov1.d(41): Error: identifier or new keyword expected following `(...)`. fail_compilation/misc_parser_err_cov1.d(41): Error: expression expected, not `;` fail_compilation/misc_parser_err_cov1.d(42): Error: found `}` when expecting `;` following statement `(__error) + 0` on line fail_compilation/misc_parser_err_cov1.d(41) -fail_compilation/misc_parser_err_cov1.d(43): Error: found `End of File` when expecting `}` following compound statement +fail_compilation/misc_parser_err_cov1.d(43): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/misc_parser_err_cov1.d(33): unmatched `{` --- */ module misc_parser_err_cov1; diff --git a/compiler/test/fail_compilation/missingbrace.d b/compiler/test/fail_compilation/missingbrace.d new file mode 100644 index 0000000000..5c8166eaa6 --- /dev/null +++ b/compiler/test/fail_compilation/missingbrace.d @@ -0,0 +1,10 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/missingbrace.d(11): Error: matching `}` expected following compound statement, not `End of File` +fail_compilation/missingbrace.d(9): unmatched `{` +--- +*/ +void main() +{ + int a; diff --git a/compiler/test/fail_compilation/unmatchedbrace.d b/compiler/test/fail_compilation/unmatchedbrace.d new file mode 100644 index 0000000000..30dc3b5d90 --- /dev/null +++ b/compiler/test/fail_compilation/unmatchedbrace.d @@ -0,0 +1,10 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/unmatchedbrace.d(11): Error: matching `}` expected, not `End of File` +fail_compilation/unmatchedbrace.d(8): unmatched `{` +--- +*/ +@safe { + // + struct S {}