Bug 22243 – Storage classes should be inferred for parameters of function literals
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-26T21:18:01Z
Last change time
2021-10-25T05:13:51Z
Assigned to
No Owner
Creator
Paul Backus
Comments
Comment #0 by snarwin+bugzilla — 2021-08-26T21:18:01Z
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.
Comment #1 by pro.mathias.lang — 2021-10-25T05:13:51Z
This has been reported a few times. I couldn't find the original comment, but Kenji mentioned he did so as many people (like Maxim in the linked issue) wanted to have to write `ref` & co.
However, this is something I agree should happen, and the change to make it work is minor. It was brought up at the last DLF meeting.
*** This issue has been marked as a duplicate of issue 11316 ***