D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22278 - [Conditional Compilation] there should be in and out flags
Summary: [Conditional Compilation] there should be in and out flags
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-09-04 15:48 UTC by João Lourenço
Modified: 2021-10-05 09:32 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description João Lourenço 2021-09-04 15:48:10 UTC
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 Dlang Bot 2021-09-04 15:56:33 UTC
@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
Comment 2 Dlang Bot 2021-10-05 09:32:24 UTC
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