www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13423] New: Allow covariant assignment of lambda to delegate

https://issues.dlang.org/show_bug.cgi?id=13423

          Issue ID: 13423
           Summary: Allow covariant assignment of lambda to delegate
                    variable
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Code:
------
void main() {
        void delegate(char) dg = (dchar) {};
}
------

Compiler output (2.067alpha):
------
test.d(2): Error: cannot implicitly convert expression (__lambda1) of type void
delegate(dchar _param_0) pure nothrow  nogc  safe to void delegate(char)
test.d(2): Error: cannot implicitly convert expression (__lambda1) of type void
delegate(dchar _param_0) pure nothrow  nogc  safe to void delegate(char)
------

There is no possible harm that can come from calling a pure nothrow  nogc  safe
delegate via an impure/throwing/allocating/unsafe delegate pointer, so this
assignment should be allowed. (Obviously, though, assigning in the other
direction cannot be allowed.)

--
Sep 04 2014