Bug 24602 – Internal compiler error: failed to detect static initialization of associative array

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2024-06-12T16:15:21Z
Last change time
2024-07-01T14:52:53Z
Keywords
pull
Assigned to
No Owner
Creator
sahan.h.fernando

Comments

Comment #0 by sahan.h.fernando — 2024-06-12T16:15:21Z
The following code fails to compile on dmd, with the error message below. Code: ``` class Set { bool[string] s; } Set newSet(string[] values) { auto s = new Set(); foreach (v; values) { s.s[v] = true; } return s; } class Bar { Set x = newSet(["a", "b"]); } void main() {} ``` Compile command: ``` $ dmd repro.d ``` Error message: ``` repro.d(8): Error: internal compiler error: failed to detect static initialization of associative array ``` I hit this on `DMD64 D Compiler v2.108.1`, as packaged by the arch linux maintainers (Looking through the build files for the package at https://gitlab.archlinux.org/archlinux/packaging/packages/dmd/-/blob/1-2.108.1-1/PKGBUILD?ref_type=tags, it doesn't seem like there were any patches applied by them, so I believe this must be a bug in the compiler).
Comment #1 by sahan.h.fernando — 2024-06-12T18:52:00Z
Looking into this a bit more (running against all versions), it appears that it used to fail to compile with a proper error message, but now fails with an internal compiler error message. I assume this would be considered a regression then, since the ICE message only occurs from 2.106.1 onwards. ``` Up to 2.074.1: Failure with output: onlineapp.d(8): Error: non-constant expression ["a":true, "b":true] 2.075.1 to 2.100.2: Failure with output: onlineapp.d(8): Error: non-constant expression `["a":true, "b":true]` 2.101.2 to 2.105.3: Failure with output: ----- onlineapp.d(8): Error: static initializations of associative arrays is not allowed. onlineapp.d(8): associative arrays must be initialized at runtime: https://dlang.org/spec/hash-map.html#runtime_initialization ----- Since 2.106.1: Status -4 with output: onlineapp.d(8): Error: internal compiler error: failed to detect static initialization of associative array ```
Comment #2 by dlang-bot — 2024-06-17T18:31:18Z
@dkorpel created dlang/dmd pull request #16592 "Fix Bugzilla 24602 - Internal compiler error: failed to detect static…" fixing this issue: - Fix Bugzilla 24602 - Internal compiler error: failed to detect static initialization of associative array https://github.com/dlang/dmd/pull/16592
Comment #3 by dlang-bot — 2024-06-17T23:24:41Z
dlang/dmd pull request #16592 "Fix Bugzilla 24602 - Internal compiler error: failed to detect static…" was merged into stable: - 17200412f5d1ebcf73fca199d86aaba1ced1bdfe by Dennis Korpel: Fix Bugzilla 24602 - Internal compiler error: failed to detect static initialization of associative array https://github.com/dlang/dmd/pull/16592
Comment #4 by dlang-bot — 2024-07-01T14:52:53Z
dlang/dmd pull request #16642 "merge stable" was merged into master: - 3e92cca51d068a4fa4a78fd677d1e9279a5adccf by Dennis Korpel: Fix Bugzilla 24602 - Internal compiler error: failed to detect static initialization of associative array https://github.com/dlang/dmd/pull/16642