D2: immutable/const and delegates
klickverbot
see at klickverbot.at
Wed Sep 8 02:46:56 PDT 2010
I always thought I had understood the new const/immutable system of D2.
But now this:
---
import std.stdio;
class A {
void setI( int newI ) {
i = newI;
}
int i;
}
void main() {
immutable a = new immutable(A);
writefln( "Before: %s", a.i );
( &a.setI )( 42 );
writefln( "After: %s", a.i );
}
---
I would expect this not to compile, but for some reason it does (and the
assignment works, a.i is 42 after the call to setI).
Am I severely misunderstanding something here, or is this a rather big
hole in the type system?
More information about the Digitalmars-d
mailing list