digitalmars.D.learn - unexpected noreturn behavior
- WebFreak001 (13/13) Apr 21 2022 What would you expect for this code?
- rikki cattermole (4/4) Apr 21 2022 noreturn is the bottom type which can implicitly convert to any type,
- WebFreak001 (10/14) Apr 21 2022 ok so I guess all the `isSomething(T)` functions must be written
- rikki cattermole (3/3) Apr 21 2022 Could we add a check for this in DScanner?
- Dennis (11/13) Apr 21 2022 What issue do you have with it returning `true`? Note that this
- Paul Backus (5/9) Apr 21 2022 Presumably the problem is that if you write something like
What would you expect for this code? ```d 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.
Apr 21 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
Apr 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#noreturnok so I guess all the `isSomething(T)` functions must be written like this then: ```d 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.
Apr 21 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.
Apr 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: ```D safe: import std.sumtype; void main() { SumType!(int, string) s = assert(0); } ```
Apr 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: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`.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`?
Apr 21 2022