Discussion Thread: DIP 1034--Add a Bottom Type (reboot)--Community Review Round 1
Paul Backus
snarwin at gmail.com
Wed May 6 15:50:21 UTC 2020
On Wednesday, 6 May 2020 at 11:04:06 UTC, Mike Parker wrote:
> This is the discussion thread for the first round of Community
> Review of DIP 1034, "Add a Bottom Type (reboot)":
>
> https://github.com/dlang/DIPs/blob/15081980cd393e21218da6836321ed37ebc48dd3/DIPs/DIP1034.md
In one of the examples, it is asserted that there is no way to
use `assert(0)` in a switch-like higher-order function that uses
lambdas for its cases (such as sumtype's `match`).
> In a switch statement, it is possible to add a case default:
> assert(0);. This is not possible when using lambda-handlers to
> simulate a switch, like the sumtype package does:
This is not strictly true. It can be done by specifying the
return type of the `assert(0)` lambda explicitly, rather than
relying on type inference:
int round(Var v) {
return v.match!(
(int x) => return x,
(double x) => return cast(int) x,
function int (other) { assert(0); } // compiles
);
}
More information about the Digitalmars-d
mailing list