Bug 15752 – Diagnostic: Better Error Message for Assigning Incorrect AA Empty Value
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-04T02:55:31Z
Last change time
2023-09-12T08:55:26Z
Keywords
bootcamp, diagnostic, pull
Assigned to
No Owner
Creator
Jack Stouffer
Comments
Comment #0 by jack — 2016-03-04T02:55:31Z
Because of the use of [] to enclose AA assignment, one could be forgiven in accidentally doing something like this:
void main() {
int[int] a = [];
}
Which results in the very unhelpful message:
Error: can't have associative array key of void
Of course, the right answer is to use null, but again, the similarities with array literals one could be expected to make this mistake. The error message is also different when trying to do this for an optional function parameter.
void func(int[int] b = []) {
}
void main() {
func();
}
Error: cannot implicitly convert expression ([]) of type void[] to int[int]
The message should be something like this:
Error: can't have associative array key of void. Perhaps you meant to initialize an empty AA with null?
Comment #1 by dlang-bot — 2023-09-11T12:37:05Z
@ntrel created dlang/dmd pull request #15599 "Fix Issue 15752 - Better Error Message for Assigning Incorrect AA Emp…" fixing this issue:
- Fix Issue 15752 - Better Error Message for Assigning Incorrect AA Empty Value
Also show location of value with missing index in initializer.
https://github.com/dlang/dmd/pull/15599
Comment #2 by dlang-bot — 2023-09-12T08:55:26Z
dlang/dmd pull request #15599 "Fix Issue 15752 - Better Error Message for Assigning Incorrect AA Emp…" was merged into master:
- 776919e2a76bf7619cb628cd052cca3443028b40 by Nick Treleaven:
Fix Issue 15752 - Better Error Message for Assigning Incorrect AA Empty Value
Also show location of value with missing index in initializer.
https://github.com/dlang/dmd/pull/15599