Bug 22278 – [Conditional Compilation] there should be in and out flags

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-09-04T15:48:10Z
Last change time
2021-10-05T09:32:24Z
Keywords
pull
Assigned to
No Owner
Creator
João Lourenço

Comments

Comment #0 by jlourenco5691 — 2021-09-04T15:48:10Z
Currently, there is no way within the language to check if contracts are being compiled or not. The only way is to use `version(assert)`, which accomplishes that in a way. The problem is if the user runs unit tests in release mode. The assertions are compiled but contracts are not, leading to the failure of all `assertThrown` checks. There are ways to still compile without failures. DMD has the `check` flag that can override the build mode. To run unit tests in release with `in` contracts on, one can pass `-check=in=on` to the compiler. But this still isn't favorable because the flag isn't shared across compilers. LDC for example has `--enable-preconditions=1`. Having a language version can standardize this and make it easier when working with this. I propose implementing the version flags: D_PreConditions and D_PostConditions for `in` and `out` contracts respectively.
Comment #1 by dlang-bot — 2021-09-04T15:56:33Z
@iK4tsu created dlang/dmd pull request #13048 "Add version conditions for in and out contracts" fixing this issue: - src.dmd.mars: add version condition D_PostConditions Fixes Issue #22278 Signed-off-by: João Lourenço <[email protected]> https://github.com/dlang/dmd/pull/13048
Comment #2 by dlang-bot — 2021-10-05T09:32:24Z
dlang/dmd pull request #13048 "Fix Issue 22278 - [Conditional Compilation] there should be in and out flags" was merged into master: - f83aedde68746ae14e6edf6100522192e5975ff7 by João Lourenço: src.dmd.mars: add version condition D_PostConditions Fixes Issue #22278 Signed-off-by: João Lourenço <[email protected]> https://github.com/dlang/dmd/pull/13048