Spec: can a class method change the type of the object (vtable) ?

Nick Treleaven nick at geany.org
Mon Mar 18 12:44:46 UTC 2024


On Sunday, 17 March 2024 at 12:47:49 UTC, Johan wrote:
> 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
>     }
> ```

With dmd v2.108.0-rc.1 I get:
```
thislval.d(7): Error: cannot modify expression `this` because it 
is not an lvalue
```
`this` was changed to be an lvalue for a few releases recently, 
see:
https://issues.dlang.org/show_bug.cgi?id=24157


More information about the Digitalmars-d mailing list