Strage class' with invariant() {} function behaviour
mumba
qniol at o2.pl
Wed Oct 8 11:34:08 PDT 2008
Hello people.
Check this out, and explain please.
class Foo {
invariant(Object) bar() {
return new invariant(Object); //return sth caller cannot change
}
}
So far, so good. Now:
class Foo {
invariant() {} //some design by contract stuff, nothing related to type's storage classes
Object bar() { //less restrictive version of the previous func
return new Object;
}
}
So far so good. Now let's make a fusion:
class Foo {
invariant() {}
invariant(Object) bar() {
return new invariant(Object);
}
}
BANG! (dmd v2.014)
variable test.Foo.bar.__result cannot modify invariant
...
Of course, I have some theories, but I wouldn't come here if they were good, so I'll keep them for myself. Tell me yours.
cheers.
More information about the Digitalmars-d-learn
mailing list