D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20169 - Cannot allocate immutable class on the stack with scope
Summary: Cannot allocate immutable class on the stack with scope
Status: RESOLVED DUPLICATE of issue 19272
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-26 14:05 UTC by Atila Neves
Modified: 2020-07-06 03:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Atila Neves 2019-08-26 14:05:35 UTC
----------------------
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 Mathias LANG 2020-07-06 03:36:38 UTC

*** This issue has been marked as a duplicate of issue 19272 ***