Bug 5685 – [AA] Wrong code & accepted incavlid code using static array as key type in associative array

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-03-02T15:55:52Z
Last change time
2023-06-16T06:37:01Z
Keywords
accepts-invalid, wrong-code
Assigned to
No Owner
Creator
David Simcha

Comments

Comment #0 by dsimcha — 2011-03-02T15:55:52Z
The following (arguably valid, arguably invalid) code compiles successfully but produces wrong results at runtime: void main() { int[2] foo = [1, 2]; string[int[2]] aa; aa[foo] = ""; assert([1, 2] in aa); // FAILS } It should either be a compiler error (if the literal [1, 2] is treated as a dynamic array and polymorphism between dynamic and static arrays is disallowed) or it should work.
Comment #1 by verylonglogin.reg — 2014-03-09T00:28:53Z
This is `accepts-invalid` part of the issue. The following code compiles but shouldn't just like in function call case: --- void main() { int[] a; int[int[1]] aa; const b = a in aa; } --- This is `wrong-code` part of the issue: --- void main() { int[1] a = [2]; int[int[1]] aa; aa[a] = 3; assert([2] in aa); // fails } --- Here `[2]` isn't converted to static array but dynamic array address is passed to `_aaInX` and the treated to be an address of a static array causing undefined behavior.
Comment #2 by dlang-bugzilla — 2023-06-16T06:37:01Z
Fixed in 2.082 (https://github.com/dlang/dmd/pull/8516). *** This issue has been marked as a duplicate of issue 19112 ***