Bug 23932 – Slot is allocated before evaluating the value during associative array initialization

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-05-20T19:52:14Z
Last change time
2024-12-13T19:29:12Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
Vladimir Panteleev
Moved to GitHub: dmd#18169 →

Comments

Comment #0 by dlang-bugzilla — 2023-05-20T19:52:14Z
//////////////////// test.d //////////////////// class C { int[int] aa; this() { try { aa[42] = { if (true) throw new Exception("oops"); else return 9; }(); } catch (Exception e) {} } } void main() { auto c = new C; assert(c.aa.length == 0); } //////////////////////////////////////////////// This allows obtaining default-initialized objects with `@disable this()`. The order of operations needs to be changed. The value to be assigned to the AA must be evaluated first, and only then a slot should be allocated for the value to be moved into. Another example which illustrates the problem: //////////// test.d /////////// final class C { int[int] aa; this() { aa[42] = getValue(); } int getValue() { assert(aa.length == 0); return 0; } } void main() { auto c = new C; } ///////////////////////////////
Comment #1 by dlang-bot — 2023-05-23T09:17:39Z
@RazvanN7 created dlang/dmd pull request #15264 "Fix Issue 23932 - Slot is allocated before evaluating the value during associative array initialization" fixing this issue: - Fix Issue 23932 - Slot is allocated before evaluating the value during associative array initialization https://github.com/dlang/dmd/pull/15264
Comment #2 by robert.schadek — 2024-12-13T19:29:12Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18169 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB