www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20169] New: Cannot allocate immutable class on the stack with

https://issues.dlang.org/show_bug.cgi?id=20169

          Issue ID: 20169
           Summary: Cannot allocate immutable class on the stack with
                    scope
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: atila.neves gmail.com

----------------------
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`.

--
Aug 26 2019