Bug 22004 – [REG2.097] Error: mismatched function return type inference of `void` and `noreturn`

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-08T09:45:00Z
Last change time
2021-10-13T13:17:29Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Vladimir Panteleev

Comments

Comment #0 by dlang-bugzilla — 2021-06-08T09:45:00Z
/////////////////////////// test.d /////////////////////////// alias fun = _ => {}(); alias gun = _ => assert(0); auto bun(bool b) { if (b) return gun(0); else return fun(0); } ////////////////////////////////////////////////////////////// test.d(3): Error: mismatched function return type inference of `void` and `noreturn` The return type of bun should be void, as in fun's. If the gun and fun calls are swapped, the error message changes: test.d(3): Error: cannot return non-void from `void` function But, "returning" a "noreturn" value should be allowed from a void function. Worked in 2.096.0.
Comment #1 by moonlightsentinel — 2021-06-08T09:55:49Z
Probably worked in 2.096 because both lambdas were inferred to return void
Comment #2 by dlang-bot — 2021-10-06T19:05:47Z
@MoonlightSentinel created dlang/dmd pull request #13135 "Issue 22004 - Allow noreturn returns from void functions" mentioning this issue: - Issue 22004 - Allow noreturn returns from void functions This is valid because - noreturn is convertible to any type (incl. void) - the program will abort/throw while evaluating the expression and hence never actually return a value This means that the ReturnStatement` can be replaced by the standalone expression without changing the behaviour of the program. --- Doesn't fix 22004 because the supplied example requires further changes to accomodate for `return <noreturn>;` and subsequent `return;`'s. https://github.com/dlang/dmd/pull/13135
Comment #3 by dlang-bot — 2021-10-09T09:07:05Z
dlang/dmd pull request #13135 "Issue 22004 - Allow noreturn returns from void functions" was merged into stable: - 3d83852dc2f36b76a83cab6a21b6461d84012af4 by MoonlightSentinel: Issue 22004 - Allow noreturn returns from void functions This is valid because - `noreturn` is convertible to any type (incl. `void`) - the program will abort/throw while evaluating the expression and hence never actually return a value This means that the `ReturnStatement` can be replaced by the standalone expression without changing the behaviour of the program. --- Doesn't fix 22004 because the supplied example requires further changes to accomodate for `return <noreturn>;` and subsequent `return;`'s during the return type inference. https://github.com/dlang/dmd/pull/13135
Comment #4 by dlang-bot — 2021-10-10T12:58:36Z
@MartinNowak created dlang/dmd pull request #13149 "merge stable" mentioning this issue: - Issue 22004 - Allow noreturn returns from void functions (#13135) This is valid because - `noreturn` is convertible to any type (incl. `void`) - the program will abort/throw while evaluating the expression and hence never actually return a value This means that the `ReturnStatement` can be replaced by the standalone expression without changing the behaviour of the program. --- Doesn't fix 22004 because the supplied example requires further changes to accomodate for `return <noreturn>;` and subsequent `return;`'s during the return type inference. https://github.com/dlang/dmd/pull/13149
Comment #5 by dlang-bot — 2021-10-10T23:13:22Z
dlang/dmd pull request #13149 "merge stable" was merged into master: - 0fabd110dd146eaf868e1195e9bff172d3c9ba1c by Florian: Issue 22004 - Allow noreturn returns from void functions (#13135) This is valid because - `noreturn` is convertible to any type (incl. `void`) - the program will abort/throw while evaluating the expression and hence never actually return a value This means that the `ReturnStatement` can be replaced by the standalone expression without changing the behaviour of the program. --- Doesn't fix 22004 because the supplied example requires further changes to accomodate for `return <noreturn>;` and subsequent `return;`'s during the return type inference. https://github.com/dlang/dmd/pull/13149
Comment #6 by dlang-bot — 2021-10-11T00:36:00Z
@MoonlightSentinel created dlang/dmd pull request #13155 "Fix 22004 - Subsequent return statements override inferred noreturn return type" fixing this issue: - Fix 22004 - Subsequent return statements override inferred noreturn... ... return type. Return type inference used to commit to `noreturn` when encountering a return statement producing a `noreturn` value. This was problematic when the function contained subsequent `void` returns, raising an error regarding missmatched function type inference even though `void` and `noreturn` are compatible (neither produce an actual value). This patch changes the code to let `noreturn` be overriden by `void`. https://github.com/dlang/dmd/pull/13155
Comment #7 by dlang-bot — 2021-10-11T05:13:25Z
dlang/dmd pull request #13155 "Fix 22004 - Subsequent return statements override inferred noreturn return type" was merged into stable: - 8f4be075c727594c203cc0a36fea9d518c1f1d30 by MoonlightSentinel: Fix 22004 - Subsequent return statements override inferred noreturn... ... return type. Return type inference used to commit to `noreturn` when encountering a return statement producing a `noreturn` value. This was problematic when the function contained subsequent `void` returns, raising an error regarding missmatched function type inference even though `void` and `noreturn` are compatible (neither produce an actual value). This patch changes the code to let `noreturn` be overriden by `void`. https://github.com/dlang/dmd/pull/13155
Comment #8 by dlang-bot — 2021-10-13T13:17:29Z
dlang/dmd pull request #13164 "Merge stable" was merged into master: - 8989d6653d5fa5e1d2c20fa30dabeda54c0f283f by MoonlightSentinel: Fix 22004 - Subsequent return statements override inferred noreturn... ... return type. Return type inference used to commit to `noreturn` when encountering a return statement producing a `noreturn` value. This was problematic when the function contained subsequent `void` returns, raising an error regarding missmatched function type inference even though `void` and `noreturn` are compatible (neither produce an actual value). This patch changes the code to let `noreturn` be overriden by `void`. https://github.com/dlang/dmd/pull/13164