Bug 20169 – Cannot allocate immutable class on the stack with scope
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-08-26T14:05:35Z
Last change time
2020-07-06T03:36:38Z
Assigned to
No Owner
Creator
Atila Neves
Comments
Comment #0 by atila.neves — 2019-08-26T14:05:35Z
----------------------
class Foo {
this(int i) immutable {}
}
void main() {
scope foo = new immutable Foo(42);
}
-----------------------
Fails to compile with:
huh.d(6): Error: cannot modify immutable expression foo
It works as expected if `auto` is used instead of `scope`.
Comment #1 by pro.mathias.lang — 2020-07-06T03:36:38Z
*** This issue has been marked as a duplicate of issue 19272 ***