Pull request https://github.com/dlang/dmd/pull/15389 for issue 24024 allows to modify `this` for classes inside functions. This is now also allowed inside contracts, which is inconsistent with other parameters.
import std.stdio;
class C
{
void f(int i)
in
{
this = null; // OK
//i = 5; // Error: cannot modify parameter `i` in contract
}
do
{
writeln(cast(void*)this); // prints null
}
}
void main()
{
C c = new C;
c.f(1);
}
Comment #1 by robert.schadek — 2024-12-13T19:30:04Z