Maybe D was wrong on contracts

Timon Gehr timon.gehr at gmx.ch
Mon Aug 17 19:10:57 UTC 2026


On 8/17/26 20:57, Quirin Schroll wrote:
> TL;DR: D’s contracts are theoretically unsound, but there’s an easy fix.
> 
> ....
> 
> Maybe C++ got something right, or rather, D got something wrong that C++ 
> got right-er:
> ....

It's not like I didn't try: https://issues.dlang.org/bugs/7584/

> ...
> I have no idea how DMD implements contract checking, but I assume it 
> wouldn’t be too difficult to skip checking postconditions if the 
> corresponding preconditions hadn’t been met. At worst, it has to store a 
> `bool` to remember that. I’d consider this a miniscule price to pay (in 
> terms of performance) for a contract semantics that is theoretically sound.
> ...

Continuing when an `in` contract fails needs to catch an `AssertError`. 
(This is already a problem.)


More information about the Digitalmars-d mailing list