Bug 18143 – in/out contracts should be implicitly 'this' const

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-30T00:51:38Z
Last change time
2021-01-25T11:18:38Z
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2017-12-30T00:51:38Z
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.
Comment #1 by ibuclaw — 2017-12-30T00:52:01Z
See also comments in issue 12901
Comment #2 by github-bugzilla — 2018-01-06T21:46:07Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/3d024cb20277826a428ac616a7324be027843122 fix Issue 18143 - in/out contracts should be implicitly 'this' const https://github.com/dlang/dmd/commit/4c7ea172c8f1c714fe85a3fda54ec2ddfc0598f1 Merge pull request #7553 from ibuclaw/issue18143 fix Issue 18143 - in/out contracts should be implicitly 'this' const merged-on-behalf-of: Mike Franklin <[email protected]>
Comment #3 by dlang-bot — 2021-01-25T11:18:38Z
dlang/dmd pull request #12153 "[dmd-cxx] Backport fixes for issue 18143 and 18719." was merged into dmd-cxx: - b6e4baefe04777e905a61c7d1291a9ed691a8698 by Iain Buclaw: fix Issue 18143 - in/out contracts should be implicitly 'this' const https://github.com/dlang/dmd/pull/12153