First Draft: opUnwrapIfTrue
Dennis
dkorpel at gmail.com
Thu Feb 26 18:03:31 UTC 2026
On Thursday, 26 February 2026 at 13:53:41 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> ```D
> if (int value = result) {
> // got a value!
> assert(value == 99);
> } else {
> // oh noes an error or default init state
> }
> ```
So after this DIP, the value in the if-condition can now be
falsey.
```D
if (int value = result)
{
// value can be 0 here
assert(value); // can fail!
}
```
This looks very confusing to me. Note that Rust's `if let
Some(value) = result
` doesn't have this problem because the `Some()` makes it
explicit that unwrapping is going on. (Also int/i32 doesn't
implicitly convert to bool there).
You list range primitives as prior work, but notably they require
the dedicated foreach keyword instead of being an invisible
overload of the old `for` statement. I think if we add unwrapping
or pattern matching to D, it should have its own syntax.
More information about the dip.development
mailing list