Issue 24745 - Better error message when creating an associative array with the wrong syntax
Summary: Better error message when creating an associative array with the wrong syntax
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2024-09-04 17:09 UTC by Lance Bachmeier
Modified: 2024-11-17 00:08 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lance Bachmeier 2024-09-04 17:09:49 UTC
If you accidentally do this when creating an AA

int[int] f = {1: 1, 2: 2};

The error message is confusing:

Error: comma expected separating field initializers
Error: expression expected, not `:`

In this case, the error message could include something to indicate that [] are used to create an associative array. It's also unclear what the error message in its current form means, since {1: 1, 2: 2} is designated initializer syntax. The only problem is that 1 and 2 are not valid names.
Comment 1 Dlang Bot 2024-09-09 11:00:57 UTC
@royalpinto007 updated dlang/dmd pull request #16832 "fix 24745 - improve associative array syntax error message" fixing this issue:

- fix Bugzilla 24745 - improve associative array syntax error message
  
  Signed-off-by: royalpinto007 <royalpinto007@gmail.com>
  
  fix 24745 - issue line
  
  Signed-off-by: royalpinto007 <royalpinto007@gmail.com>

https://github.com/dlang/dmd/pull/16832
Comment 2 Dlang Bot 2024-11-17 00:08:21 UTC
dlang/dmd pull request #16832 "fix Bugzilla 24745 - improve associative array syntax error message" was merged into master:

- d4b85e9827a85bfe4f55b0fbd1c487fed7b051b9 by royalpinto007:
  fix Bugzilla 24745 - improve associative array syntax error message
  
  Signed-off-by: royalpinto007 <royalpinto007@gmail.com>

https://github.com/dlang/dmd/pull/16832