Bug 24231 – Can't emplace immutable nested class

Status
NEW
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-11-07T01:26:09Z
Last change time
2024-12-07T13:43:01Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#17468 →

Comments

Comment #0 by snarwin+bugzilla — 2023-11-07T01:26:09Z
As of DMD 2.105.3, the following program fails to compile. --- void main() { import core.lifetime; class O { int n = 123; class I { int fun() => n; } } auto buf = new void[](__traits(classInstanceSize, O.I)); emplace!(immutable(O.I))(buf, new immutable(O)); } --- The error message is: --- /usr/include/dmd/druntime/import/core/lifetime.d(116): Error: cannot modify `immutable` expression `chunk.this` /usr/include/dmd/druntime/import/core/lifetime.d(209): Error: template instance `core.lifetime.emplace!(immutable(I), immutable(O))` error instantiating test.d(14): instantiated from here: `emplace!(immutable(I), immutable(O))` --- This is caused by emplace attempting to set the .outer field of the emplaced class instance to the value of its second argument (new immutable(O)). The assignment fails, because the emplaced instance is immutable, and its fields cannot be written to.
Comment #1 by robert.schadek — 2024-12-07T13:43:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17468 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB