Fix Issue 24000 - show open bracket "{" location for Error: matching … (#15334)

* Fix Issue 24000 - show open bracket "{" location for Error: matching `}` expected

* Show unmatched brace after compound statement

* Update tests
This commit is contained in:
Nick Treleaven 2023-06-26 13:00:34 +01:00 committed by GitHub
parent 79c4ee7229
commit 55d9dc0989
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 130 additions and 88 deletions

View file

@ -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;
}

View file

@ -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__
}

View file

@ -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[()
{
;
}

View file

@ -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

View file

@ -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)

View file

@ -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 ;
}

View file

@ -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 `{`
---
*/

View file

@ -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
---
*/

View file

@ -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;
}

View file

@ -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 }

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -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 {}