Safe cast away from immutable

Iakh via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 8 14:19:44 PST 2016


On Monday, 8 February 2016 at 21:48:30 UTC, Jonathan M Davis 
wrote:

> that right now, but clearly, what it currently has is buggy,

Yeah. Looks like it just traverse params's AST and search for
exactly match with ReturnType.

The code with replaced (void, int) with (class A, class B : A)
behaves the same way as original:

import std.stdio;

class A
{
     int i;
}

class B : A
{
}

struct S
{
     A a;

     auto f() pure @safe
     {
         B b = new B;
         a = b;
         return b;
     }
}

void main() @safe
{
     S s;
     immutable a = s.f();
     A b = s.a;
     writeln(a.i);
     b.i = 1;
     writeln(a.i);
}


More information about the Digitalmars-d mailing list