diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index a7a930335ad5..fa24cb3280af 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -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) @@ -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; diff --git a/compiler/test/fail_compilation/test24745.d b/compiler/test/fail_compilation/test24745.d new file mode 100644 index 000000000000..9c7ea59929a3 --- /dev/null +++ b/compiler/test/fail_compilation/test24745.d @@ -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}; +}