Bug 15290 – length of associative array literal with duplicate keys is wrong

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-11-05T10:28:51Z
Last change time
2017-12-18T22:54:41Z
Keywords
pull
Assigned to
No Owner
Creator
Marc Schütz
See also
https://issues.dlang.org/show_bug.cgi?id=11637

Comments

Comment #0 by schuetzm — 2015-11-05T10:28:51Z
void main() { import std.stdio : writeln; ["key": 10, "key" : 20, "key" : 30].length.writeln; ["key" : 30].length.writeln; } This prints: 3 1 In general, duplicate keys in literals should probably be disallowed anyway: https://issues.dlang.org/show_bug.cgi?id=11637
Comment #1 by gassa — 2017-02-03T07:18:45Z
Stumbled across this one, too: https://forum.dlang.org/post/[email protected] My use case is as follows: foreach (i; 0..10) foreach (j; 0..10) if (pred2 (i, j)) foreach (k; 0..10) if (pred3 (i, j, k)) ... and maybe more ... { auto set = [i: true, j: true; k: true]; if (set.length == 3) { ... we found distinct i, j, k, ... } }
Comment #2 by hsteoh — 2017-12-01T00:52:32Z
Comment #3 by hsteoh — 2017-12-01T00:59:50Z
Another user on the learn forum ran into this too: http://forum.dlang.org/post/[email protected]
Comment #4 by github-bugzilla — 2017-12-01T15:22:15Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/f8f49450b8cff3842c422aec9a0d581cf4c6d438 Fix issue 15290: account for duplicated keys in AA literals. https://github.com/dlang/druntime/commit/762af06ab588073a526d75d0b7ae983bacb0adf3 Merge pull request #1980 from quickfur/aalit_dupkeys Fix issue 15290: account for duplicated keys in AA literals.
Comment #5 by github-bugzilla — 2017-12-18T22:54:41Z
Commits pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/f8f49450b8cff3842c422aec9a0d581cf4c6d438 Fix issue 15290: account for duplicated keys in AA literals. https://github.com/dlang/druntime/commit/762af06ab588073a526d75d0b7ae983bacb0adf3 Merge pull request #1980 from quickfur/aalit_dupkeys