Skip to content

Commit

Permalink
fix 24745 - improve error message when creating an associative array …
Browse files Browse the repository at this point in the history
…with the wrong syntax

Signed-off-by: royalpinto007 <[email protected]>

fix 24745 - issue line

Signed-off-by: royalpinto007 <[email protected]>
  • Loading branch information
royalpinto007 committed Sep 9, 2024
1 parent 96d630c commit 6c67dd7
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 `{}`");
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 `{}`");
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 6c67dd7

Please sign in to comment.