[Issue 24035] New: Changing this for classes is allowed in contracts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 6 15:41:34 UTC 2023
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: nobody at puremagic.com
Reporter: tim.dlang at 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);
}
--
More information about the Digitalmars-d-bugs
mailing list