www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23364] New: returning bottom type by ref should work


          Issue ID: 23364
           Summary: returning bottom type by ref should work
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: Ajieskola gmail.com

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:

core.exception.AssertError app.d(1): Accessed expression of type `noreturn`
??:? _d_assert_msg [0x43a7c8]
??:? pure nothrow ref  nogc  safe noreturn app.foo(return ref noreturn)
??:? _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);

Sep 24 2022