Thread overview
[Issue 12189] New: "out" parameters should be allowed to modify immutable values in ctors
Feb 18, 2014
Vladimir Panteleev
Feb 18, 2014
timon.gehr@gmx.ch
Feb 19, 2014
Kenji Hara
Feb 19, 2014
Vladimir Panteleev
February 18, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12189

           Summary: "out" parameters should be allowed to modify immutable
                    values in ctors
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: thecybershadow@gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-02-18 03:56:13 EET ---
void initialize(out string[] v) { v = ["Hi!"]; }

immutable string[] s;

shared static this()
{
    s = ["Hi!"];   // OK
    initialize(s); // NG
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 18, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12189


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr@gmx.ch


--- Comment #1 from timon.gehr@gmx.ch 2014-02-18 04:08:29 PST ---
string[]* ms;

void initialize(out string[] v){
    v = ["Hi!"];
    ms = &v; // oops
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12189


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2014-02-18 20:10:06 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12189



--- Comment #3 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-02-19 06:46:46 EET ---
Thanks, I didn't think about that.

If "out" did not allow escaping references then I guess it would be different.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12189


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #4 from bearophile_hugs@eml.cc 2014-02-19 01:10:59 PST ---
(In reply to comment #3)

> If "out" did not allow escaping references then I guess it would be different.

"scope out"?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------