https://issues.dlang.org/show_bug.cgi?id=24035

          Issue ID: 24035
           Summary: Changing this for classes is allowed in contracts
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nob...@puremagic.com
          Reporter: tim.dl...@t-online.de

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);
}

--

Reply via email to