<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/11/10 Daniel Murphy <span dir="ltr"><<a href="mailto:yebblies@nospamgmail.com" target="_blank">yebblies@nospamgmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
"Kenji Hara" <<a href="mailto:k.hara.pg@gmail.com">k.hara.pg@gmail.com</a>> wrote in message<br>
</div>news:mailman.339.1384090714.9546.digitalmars-d@puremagic.com...<br>
<div class="im">> 2013/11/10 Daniel Murphy <<a href="mailto:yebblies@nospamgmail.com">yebblies@nospamgmail.com</a>><br>
><br>
>> "Kenji Hara" <<a href="mailto:k.hara.pg@gmail.com">k.hara.pg@gmail.com</a>> wrote in message<br>
>> news:mailman.336.1384083327.9546.digitalmars-d@puremagic.com...<br>
>> ><br>
>> > This is valid. Because not only strongly pure function will return<br>
>> > unique<br>
>> > object.<br>
>> ><br>
>> > For example:<br>
>> >  immutable(int)[] foo(int[] iarr) pure { ... }<br>
>> >  int[] marr = foo([1,2,3]);<br>
>> >  // foo will never return the arr argument (without unsafe cast).<br>
>> ><br>
>><br>
>> This one is incorrect, the value returned from foo could be an immutable<br>
>> global.  The unique conversion is only capable of changing non-mutable to<br>
>> immutable, not the other way around.<br>
>><br>
><br>
</div><div class="im">> foo is pure, so it cannot return "immutable global".<br>
><br>
<br>
</div>Pure functions _can_ read immutable global variables.<br>
<br>
immutable x = [1, 2, 3];<br>
<br>
void main() pure<br>
{<br>
    assert(x[1] == 2);<br>
}<br>
<br>
Even if they couldn't, the immutable -> mutable conversion would still not<br>
be safe.<br>
<br>
edit: uh-oh this actually compiles.  Did you do this?<br>
<br>
eg<br>
<br>
import std.stdio;<br>
<br>
struct S<br>
{<br>
    immutable(S)* s;<br>
    this(int) immutable pure<br>
    {<br>
        s = &this;<br>
    }<br>
    int data;<br>
}<br>
<br>
immutable(S)* makes() pure<br>
{<br>
    return new immutable S(0);<br>
}<br>
<br>
void main()<br>
{<br>
    S* s = makes(); // s is mutable and contains an immutable reference to<br>
itself<br>
    pragma(msg, typeof(s)); // mutable<br>
    pragma(msg, typeof(s.s)); // immutable<br>
    writefln("%s", s);   // same address<br>
    writefln("%s", s.s); // same address<br>
    //s.s.data = 7; // this is immutable<br>
    s.data = 3; // but this is not!!!<br>
}<br></blockquote><div><br></div><div>Ohhhh, it is definitely a bug. And that was introduced by MY pull requests (I know that).</div><div>We must fix the type system hole ASAP!</div><div><br></div><div><a href="https://d.puremagic.com/issues/show_bug.cgi?id=11503">https://d.puremagic.com/issues/show_bug.cgi?id=11503</a><br>
</div></div><br></div><div class="gmail_extra">Kenji Hara</div></div>