[Issue 24169] Confusion between array literal and associative array literal
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 29 17:17:40 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24169
--- Comment #5 from Dennis <dkorpel at live.nl> ---
(In reply to Walter Bright from comment #4)
> The change to add associative array literals did exactly that.
A change in the past had an unfortunate side effect. How does this justify
adding a new confusing rule? Imagine someone wrote this:
```
auto x =
[
0: 10,
4: 40,
];
void main()
{
x.byKeyValue.each!writeln;
}
```
Then one day someone adds an entry:
```
auto x =
[
0: 10,
4: 40,
5: 50,
];
```
With the proposed scheme, x would suddenly change type resulting in errors like
`Error: none of the overloads of template `object.byKeyValue` are callable
using argument types `!()(int[])`. How is the programmer supposed to know what
happened here?
--
More information about the Digitalmars-d-bugs
mailing list