xxxxxxxxxx
import std.exception;
immutable struct S { int i; }
struct Struct
{
union
{
S s;
}
void test()
{
static struct Wrapper
{
S s;
this(S s)
{
this.s = s; // the one operation allowed to assign immutable fields
}
}
Wrapper* wrapper = cast(Wrapper*) &s;
wrapper.__ctor(S(5)); // fake placement new
}
}
void main()
{
Struct value;
enforce(value.s.i == 0);
value.test;
enforce(value.s.i == 5);
}