User:Schuetzm/isolated
Isolated
Currently, this works:
void main() {
immutable int* p = new int;
}
This doesn't:
struct S {
int* p;
}
void main() {
auto tmp = new S;
tmp.p = new int;
immutable S* s = tmp; // Error: cannot implicitly convert expression (tmp) of type S* to immutable(S*)
}
But if we wrap the construction in a pure function, it does work:
struct S {
int* p;
}
S* makeS() pure {
auto tmp = new S;
tmp.p = new int;
return tmp;
}
void main() {
immutable S* s = makeS();
}
By utilizing deadalnix' "isolated" idea, we can make the second example work, too. This will be useful for incremental construction of complex immutable data structures, as well as data structures that should be transferred to another thread.
TODO: specify the rules (islands concept)