Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 24745 - improve associative array syntax error message #16832

Draft
wants to merge 1 commit into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
{

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

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