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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 11 20:13:30 PST 2013


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 at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at 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: -------


More information about the Digitalmars-d-bugs mailing list