"I told you so": noreturn sucks a leech and has virtually no utility
Stefan Koch
uplink.coder at googlemail.com
Fri Oct 15 19:10:42 UTC 2021
On Friday, 15 October 2021 at 18:59:55 UTC, Timon Gehr wrote:
> On 10/15/21 8:52 PM, Basile B. wrote:
>>
>> No, you can use it everywhere a Type can be used: cast to
>> type, TemplateTypeParameter, VarDeclaration type, etc. And
>> most of the time this is obviously not useful and has to be
>> rejected, i.e during the semantic, i.e by the front-end.
>
> I don't think rejecting everything that's "obviously not
> useful" is the right approach. It just causes headaches for
> generic code.
Seconded. The point of noreturn is precisely to reject less.
The no-return type has no values which means reading or writing
that type is merely undefined behavior. It doesn't have to be
rejected.
void x; // special cased to be rejected.
noreturn x; // totally fine, just don't read or write to it.
with noreturn (and removing void/ or replacing it with unit) the
statement any type may be used to create a variable of that type
is true.
Leading to less special casing and possible contradictions in the
type system.
How the backend may deal with a variable such as this, is
actually easy.
just ignore it. It doesn't need any storage and will never be
referenced in well formed code.
More information about the Digitalmars-d
mailing list