www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11503] New: Type system breaking caused by implicit conversion for the value returned from pure function

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11503

           Summary: Type system breaking caused by implicit conversion for
                    the value returned from pure function
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2013-11-11 20:13:27 PST ---
From: http://forum.dlang.org/post/l5o3tq$jof$1 digitalmars.com

If an immutable value is returned by pure function, compiler _must_ not
implicitly convert it to mutable.

Test case:

import std.stdio;

struct S
{
    immutable(S)* s;
    this(int) immutable pure
    {
        s = &this;
    }
    int data;
}

immutable(S)* makes() pure
{
    return new immutable S(0);
}

void main()
{
    S* s = makes(); // s is mutable and contains an immutable reference to
itself
    pragma(msg, typeof(s)); // mutable
    pragma(msg, typeof(s.s)); // immutable
    writefln("%s", s);   // same address
    writefln("%s", s.s); // same address
    //s.s.data = 7; // this is immutable
    s.data = 3; // but this is not!!!
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11503


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com


--- Comment #1 from yebblies <yebblies gmail.com> 2013-11-12 18:31:46 EST ---
Simpler example:

import std.stdio;

immutable int[] x = [1, 2, 3];

auto makes() pure
{
    return x;
}

void main()
{
    auto a = x;
    int[] b = makes();
    writefln("%s %s", a.ptr, b.ptr);
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11503



--- Comment #2 from Andrei Alexandrescu <andrei erdani.com> 2014-01-12 10:08:39
PST ---
Placed a $150 bounty.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11503


David Nadlinger <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code klickverbot.at


--- Comment #3 from David Nadlinger <code klickverbot.at> 2014-01-12 11:05:27
PST ---
Seems to be a fairly simple issue. Regression-testing a fix right now.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11503


David Nadlinger <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #4 from David Nadlinger <code klickverbot.at> 2014-01-12 11:27:17
PST ---
https://github.com/D-Programming-Language/dmd/pull/3085

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11503


David Nadlinger <code klickverbot.at> changed:

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


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