Skip to content

Commit

Permalink
fix Bugzilla 24745 - improve associative array syntax error message
Browse files Browse the repository at this point in the history
Signed-off-by: royalpinto007 <royalpinto007@gmail.com>

fix 24745 - issue line

Signed-off-by: royalpinto007 <royalpinto007@gmail.com>
  • Loading branch information
royalpinto007 committed Sep 9, 2024
1 parent 96d630c commit 069ce3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -6791,7 +6791,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
{

if (commaExpected)
error("comma expected separating field initializers");
error("incorrect syntax for associative array, expected `[]`, found `{}`");

Check warning on line 6794 in compiler/src/dmd/parse.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/parse.d#L6794

Added line #L6794 was not covered by tests
const t = peek(&token);
Identifier id;
if (t.value == TOK.colon)
Expand Down Expand Up @@ -6822,7 +6822,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer

default:
if (commaExpected)
error("comma expected separating field initializers");
error("incorrect syntax for associative array, expected `[]`, found `{}`");

Check warning on line 6825 in compiler/src/dmd/parse.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/parse.d#L6825

Added line #L6825 was not covered by tests
auto value = parseInitializer();
_is.addInit(null, value);
commaExpected = true;
Expand Down
18 changes: 18 additions & 0 deletions compiler/test/fail_compilation/test24745.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://issues.dlang.org/show_bug.cgi?id=24745

/*
TEST_OUTPUT:
---
fail_compilation/test24745.d(17): Error: incorrect syntax for associative array, expected `[]`, found `{}`
fail_compilation/test24745.d(17): Error: expression expected, not `:`
fail_compilation/test24745.d(17): Error: incorrect syntax for associative array, expected `[]`, found `{}`
fail_compilation/test24745.d(17): Error: incorrect syntax for associative array, expected `[]`, found `{}`
fail_compilation/test24745.d(17): Error: expression expected, not `:`
fail_compilation/test24745.d(17): Error: incorrect syntax for associative array, expected `[]`, found `{}`
---
*/

void main()
{
int[int] f = {1: 1, 2: 2};
}

0 comments on commit 069ce3c

Please sign in to comment.