Bug 12189 – "out" parameters should be allowed to modify immutable values in ctors
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-17T17:56:00Z
Last change time
2014-02-19T01:10:59Z
Assigned to
nobody
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2014-02-17T17:56:13Z
void initialize(out string[] v) { v = ["Hi!"]; }
immutable string[] s;
shared static this()
{
s = ["Hi!"]; // OK
initialize(s); // NG
}
Comment #1 by timon.gehr — 2014-02-18T04:08:29Z
string[]* ms;
void initialize(out string[] v){
v = ["Hi!"];
ms = &v; // oops
}
Comment #2 by k.hara.pg — 2014-02-18T20:10:06Z
As Timon shows, accepting variable initialization via out parameter will make a hole in type system, because out parameter should have mutable type.
So this is impossible enhancement.
Comment #3 by dlang-bugzilla — 2014-02-18T20:46:46Z
Thanks, I didn't think about that.
If "out" did not allow escaping references then I guess it would be different.
Comment #4 by bearophile_hugs — 2014-02-19T01:10:59Z
(In reply to comment #3)
> If "out" did not allow escaping references then I guess it would be different.
"scope out"?