Hi all,
I am looking for a (legal D) counterexample where a class method alters the vtable of the object it is called on. In other words, a counterexample where the following transformation is invalid:
class A {
void foo();
...
}
void g() {
A a = new A();
a.foo();
a.foo();
}
---Transformed into --->
void g() {
A a = new A();
a.A.foo(); // devirtualized
a.A.foo(); // devirtualized because `A.foo(a)` may not change the type of `a`.
}
Although accepted by the compiler currently, I believe this is forbidden by the spec (can't find it, if it is not in the spec it should be added):
void foo() {
this = new B(); // illegal D code
}
Thanks,
Johan