Bug 24745 – Better error message when creating an associative array with the wrong syntax
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-09-04T17:09:49Z
Last change time
2024-11-17T00:08:21Z
Keywords
pull
Assigned to
No Owner
Creator
Lance Bachmeier
Comments
Comment #0 by lance — 2024-09-04T17:09:49Z
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.