[Issue 15752] New: Diagnostic: Better Error Message for Assigning Incorrect AA Empty Value
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Mar 3 18:55:31 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15752
Issue ID: 15752
Summary: Diagnostic: Better Error Message for Assigning
Incorrect AA Empty Value
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: jack at jackstouffer.com
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?
--
More information about the Digitalmars-d-bugs
mailing list