Bug 23364 – returning bottom type by ref should work

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-09-24T11:19:27Z
Last change time
2024-12-13T19:24:39Z
Assigned to
No Owner
Creator
Ate Eskola
Moved to GitHub: dmd#18124 →

Comments

Comment #0 by Ajieskola — 2022-09-24T11:19:27Z
Compiled with a recent master DMD version, flags -preview=dip1000 and -run ----------------------------- @safe ref foo(return ref noreturn arg){return arg;} @safe void main() { foo(*null); } ----------------------------- The above example crashes at runtime with the following message: ----------------------------- [email protected](1): Accessed expression of type `noreturn` ---------------- ??:? _d_assert_msg [0x43a7c8] ??:? pure nothrow ref @nogc @safe noreturn app.foo(return ref noreturn) [0x43a730] ??:? _Dmain [0x43a73e] ----------------------------- The example should run without any error, because `foo` function does not actually take or return the bottom value - only a (null) reference to one. It's the same reason why this program runs without error: ----------------------------- @safe ref foo(return ref int arg){return arg;} @safe void main() { foo(*cast(int*)null); } -----------------------------
Comment #1 by dlang-bugzilla — 2023-05-12T14:37:11Z
Worked before https://github.com/dlang/dmd/pull/14187 , though I'm not sure if this is something that should work... The conclusion makes sense to me only with a rather literal interpretation of the definition of noreturn in object - we "undo" the null pointer dereference by using "ref". With an alternative definition of noreturn, e.g. `typeof(assert(false))`, I'm not sure that this makes sense any more.
Comment #2 by robert.schadek — 2024-12-13T19:24:39Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18124 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB