DIP49 - Define qualified postblit
Kenji Hara
k.hara.pg at gmail.com
Mon Nov 11 20:14:26 PST 2013
2013/11/10 Daniel Murphy <yebblies at nospamgmail.com>
>
> "Kenji Hara" <k.hara.pg at gmail.com> wrote in message
> news:mailman.339.1384090714.9546.digitalmars-d at puremagic.com...
> > 2013/11/10 Daniel Murphy <yebblies at nospamgmail.com>
> >
> >> "Kenji Hara" <k.hara.pg at gmail.com> wrote in message
> >> news:mailman.336.1384083327.9546.digitalmars-d at puremagic.com...
> >> >
> >> > This is valid. Because not only strongly pure function will return
> >> > unique
> >> > object.
> >> >
> >> > For example:
> >> > immutable(int)[] foo(int[] iarr) pure { ... }
> >> > int[] marr = foo([1,2,3]);
> >> > // foo will never return the arr argument (without unsafe cast).
> >> >
> >>
> >> This one is incorrect, the value returned from foo could be an immutable
> >> global. The unique conversion is only capable of changing non-mutable
> to
> >> immutable, not the other way around.
> >>
> >
> > foo is pure, so it cannot return "immutable global".
> >
>
> Pure functions _can_ read immutable global variables.
>
> immutable x = [1, 2, 3];
>
> void main() pure
> {
> assert(x[1] == 2);
> }
>
> Even if they couldn't, the immutable -> mutable conversion would still not
> be safe.
>
> edit: uh-oh this actually compiles. Did you do this?
>
> eg
>
> 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!!!
> }
>
Ohhhh, it is definitely a bug. And that was introduced by MY pull requests
(I know that).
We must fix the type system hole ASAP!
https://d.puremagic.com/issues/show_bug.cgi?id=11503
Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20131112/488d7d89/attachment.html>
More information about the Digitalmars-d
mailing list