August 26, 2021
https://issues.dlang.org/show_bug.cgi?id=22243

          Issue ID: 22243
           Summary: Storage classes should be inferred for parameters of
                    function literals
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: snarwin+bugzilla@gmail.com

As of DMD 2.097.2, the following code fails to compile:

---
void delegate(ref int) dg = (x) { x++; };
---

The error message is:

---
Error: cannot implicitly convert expression `__lambda3` of type `void
delegate(int x) pure nothrow @nogc @safe` to `void delegate(ref int)`
---

The conversion fails because the inferred type of the function literal lacks the `ref` storage class for its parameter.

Since the correct storage class is unambiguous in this context, the compiler should be able to infer it, as it does for the parameter's type.

--