I'm glad throw is now an expression
Paul Backus
snarwin at gmail.com
Thu May 19 14:16:21 UTC 2022
On Thursday, 19 May 2022 at 09:11:45 UTC, Vladimir Panteleev
wrote:
> On Wednesday, 18 May 2022 at 17:35:14 UTC, Walter Bright wrote:
>> More thinking about this suggests that int+noreturn should be
>> typed as noreturn.
>
> How so? This makes sense to me:
>
> ```d
> int divide(int dividend, int divisor)
> {
> return divisor == 0
> ? assert(false, "You shall not divide by zero")
> : dividend / divisor;
> }
> ```
`?:` is different from `+` because evaluation of a `?:`
expression does not require evaluation of all of its operands.
Evaluation of a `+` expression with a `noreturn` operand is
guaranteed to evaluate the `noreturn` operand, and therefore is
guaranteed not to terminate, so the `+` expression itself can be
typed as `noreturn`.
More information about the Digitalmars-d
mailing list