On Thu, 29 Sep 2011 13:06:55 -0400, Simen Kjaeraas
<[email protected]> wrote:
On Thu, 29 Sep 2011 16:54:24 +0200, Steven Schveighoffer
<[email protected]> wrote:
I just thought of an interesting way to make a logical const object
without casts. It requires a little extra storage, but works without
changes to the current compiler (and requires no casts).
[snip]
What do people think about this?
This is what I think about it:
class A {
int n;
void delegate( ) dg;
}
pure
A createAnA( int n ) {
A result = new A;
result.n = n;
result.dg = (){ result.n++; };
return result;
}
void main( ) {
immutable A tmp = createAnA( 3 );
assert( tmp.n == 3 );
tmp.dg();
assert( tmp.n == 3 );
}
I agree this breaks immutability, and needs to be addressed. I think
probably implicit casting of delegates (or items that containe delegates)
to immutable from strong-pure functions should be disallowed.
But it's not the pattern I described, and uses a relatively new trick
(implicit immutable casting). I'll file a bug for this case.
-Steve