bottom type as parameter or local variable, does that make sense?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 14 18:32:18 UTC 2022


On Fri, Jan 14, 2022 at 07:24:22PM +0100, Timon Gehr via Digitalmars-d wrote:
> On 1/14/22 18:41, H. S. Teoh wrote:
> > But in D, whenever a variable is declared, it gets initialized to
> > its default value unless specified otherwise. Since nothing is
> > specified here, it ought to perform its default initialization, and
> > since there is no value with which it can be initialized, it ought
> > to raise a runtime exception.
> 
> I don't follow why this is necessarily desirable. E.g., if generic
> code checks whether or not a type can be default constructed, it will
> by default get a spurious "yes" answer and has to special case
> `noreturn`.

? Isn't that exactly what it should be?  If generic code checks whether
type T can be default constructed, and T happens to be noreturn, then it
would fail because noreturn.init is not constructible.  Presumably, the
code is doing this check because it's about to create a variable of type
T afterwards, so returning "yes" would lead to instantiating noreturn
variables. Why would that be a good thing?


T

-- 
The best way to destroy a cause is to defend it poorly.


More information about the Digitalmars-d mailing list