Bug 23114 – Can't use noreturn operand in arithmetic expression

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-16T14:46:32Z
Last change time
2022-07-09T16:31:59Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2022-05-16T14:46:32Z
As of DMD 2.100.0, the following program fails to compile --- void main() { auto _ = 2 + throw new Exception(""); } --- The error message is: --- bug.d(3): Error: incompatible types for `(2) + (throw new Exception("", "bug.d", 3LU, null))`: `int` and `noreturn` --- Changing the right-hand operand of the + operator to `cast(int) throw new Exception("")` causes the program to compile successfully and throw an exception at runtime, as expected. Since noreturn implicitly converts to every type, including int, this program should compile without an explicit cast.
Comment #1 by dlang-bot — 2022-05-17T17:15:18Z
@maxhaton created dlang/dmd pull request #14134 "Fix Issue 23114 - Make noreturn conversions work" fixing this issue: - Fix Issue 23114 - Make noreturn conversions work https://github.com/dlang/dmd/pull/14134
Comment #2 by bugzilla — 2022-05-17T19:38:25Z
This has nothing in particular to do with throwing expressions. The following fails for the same reason: --- noreturn foo(); int test() { return 1 + foo(); } ---
Comment #3 by dlang-bot — 2022-05-27T09:13:01Z
@maxhaton updated dlang/dmd pull request #14091 "Fix Issue 23088 - This bug is a symptom of a bad error message." fixing this issue: - Fix Issue 23114 - Make noreturn conversions work This meant adding the correct implicit conversions to the table in impcnvtab.d https://github.com/dlang/dmd/pull/14091
Comment #4 by dlang-bot — 2022-05-27T11:46:57Z
dlang/dmd pull request #14134 "Fix Issue 23114 - Make noreturn conversions work" was merged into stable: - 8d9c0a33cecc5ff281659962a723f18a7bfd168f by mhh: Fix Issue 23114 - Make noreturn conversions work https://github.com/dlang/dmd/pull/14134
Comment #5 by dlang-bot — 2022-07-09T16:31:59Z
dlang/dmd pull request #14280 "merge stable" was merged into master: - dbe0600f853466992fe8f3c3f684f520f6a15883 by mhh: Fix Issue 23114 - Make noreturn conversions work https://github.com/dlang/dmd/pull/14280