Thread overview
unexpected noreturn behavior
Apr 21, 2022
WebFreak001
Apr 21, 2022
rikki cattermole
Apr 21, 2022
WebFreak001
Apr 21, 2022
rikki cattermole
Apr 21, 2022
Dennis
Apr 21, 2022
Paul Backus
April 21, 2022

What would you expect for this code?

struct Something(Types...) {}

enum isSomethingExact(T) = is(T == Something!Types, Types...);
enum isSomething(T) = is(T : Something!Types, Types...);

pragma(msg, isSomethingExact!noreturn);
pragma(msg, isSomething!noreturn);

This currently outputs false, true which breaks my code because more concretely isSumType!(typeof(someMethod())) returns true. I can add a check for noreturn before that, but it seems a little weird that noreturn returns true for isSomething!T and functions like that in phobos.

April 22, 2022
noreturn is the bottom type which can implicitly convert to any type, including void. A value of type noreturn will never be produced and the compiler can optimize such code accordingly.

https://dlang.org/spec/type.html#noreturn
April 21, 2022

On Thursday, 21 April 2022 at 12:28:37 UTC, rikki cattermole wrote:

>

noreturn is the bottom type which can implicitly convert to any type, including void. A value of type noreturn will never be produced and the compiler can optimize such code accordingly.

https://dlang.org/spec/type.html#noreturn

ok so I guess all the isSomething(T) functions must be written like this then:

enum isSomething(T) = !is(immutable T == immutable noreturn)
    && is(T : Something!Other, Other...);

which I think is a little bug-prone, but at least that would solve my issues.

April 22, 2022
Could we add a check for this in DScanner?

Otherwise I'm not sure how else we are going to find all of these instances and fix them.
April 21, 2022

On Thursday, 21 April 2022 at 12:41:08 UTC, WebFreak001 wrote:

>

which I think is a little bug-prone, but at least that would solve my issues.

What issue do you have with it returning true? Note that this compiles:

@safe:
import std.sumtype;
void main()
{
    SumType!(int, string) s = assert(0);
}

April 21, 2022

On Thursday, 21 April 2022 at 12:54:12 UTC, Dennis wrote:

>

On Thursday, 21 April 2022 at 12:41:08 UTC, WebFreak001 wrote:

>

which I think is a little bug-prone, but at least that would solve my issues.

What issue do you have with it returning true?

Presumably the problem is that if you write something like assert(0).match!();, you get a spew of compiler errors, on account of the fact that match assumes anything that satisfies isSumType has properties like Types and get!T.