[Issue 18143] New: in/out contracts should be implicitly const
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 30 00:51:38 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=18143
Issue ID: 18143
Summary: in/out contracts should be implicitly const
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ibuclaw at gdcproject.org
The same already applies for invariants, you shouldn't be able to modify
internal state inside a in/out contract body.
e.g:
---
struct S
{
int a;
invariant
{ a = 42; } // fails, cannot modify const 'this'
this(int n)
in
{ a = 42; } // compiles -> should fail
out(result)
{ a = 42; } // compiles -> should fail
body
{ }
}
---
This is particularly problematic because program behaviour changes in release
mode.
--
More information about the Digitalmars-d-bugs
mailing list