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.
@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 <jlourenco5691@gmail.com> https://github.com/dlang/dmd/pull/13048
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 <jlourenco5691@gmail.com> https://github.com/dlang/dmd/pull/13048