Bug 11316 – Some cases of missing delegate argument type inference

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-10-21T11:26:22Z
Last change time
2023-02-28T04:49:23Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-10-21T11:26:22Z
void main() { void delegate(const int x) F0; F0 = (const int x) {}; // OK F0 = (x) {}; // OK void delegate(in int x) F1; F1 = (in int x) {}; // OK F1 = (x) {}; // OK void delegate(ref int x) F2; F2 = (ref int x) {}; // OK F2 = (x) {}; // Error void delegate(out int x) F3; F3 = (out int x) {}; // OK F3 = (x) {}; // Error } dmd 2.064beta2 gives: test.d(10): Error: cannot implicitly convert expression (__lambda6) of type void delegate(int x) pure nothrow @safe to void delegate(ref int x) test.d(13): Error: cannot implicitly convert expression (__lambda8) of type void delegate(int x) pure nothrow @safe to void delegate(out int x)
Comment #1 by maxim — 2013-10-21T12:06:20Z
I think parameter attribute should be provided for explicitly stating that parameter 'x' will be passed in a specific way, so the fact that void delegate(ref int x) F2; F2 = (ref int x) {}; // OK F2 = (x) {}; // Error void delegate(out int x) F3; F3 = (out int x) {}; // OK F3 = (x) {}; // Error is rejected may be a good thing (my guess why first examples are compiled is because qualifiers and attributes are trated separately, and 'in' is alias for 'const'). On the other hand, probably having attribute only in variable declaration is enough and such bahavior may have value for generic programming.
Comment #2 by pro.mathias.lang — 2021-10-25T05:13:51Z
*** Issue 22243 has been marked as a duplicate of this issue. ***
Comment #3 by snarwin+bugzilla — 2023-01-07T22:25:06Z
*** Issue 9423 has been marked as a duplicate of this issue. ***
Comment #4 by dlang-bot — 2023-02-27T23:43:58Z
@Geod24 created dlang/dmd pull request #14929 "Fix 11316: Infer storage class of parameters with function literals" fixing this issue: - Fix 11316: Infer storage class of parameters with function literals This will allow improving functional style code by seamlessly adding `ref` (or `in`) and having the compiler do the job. https://github.com/dlang/dmd/pull/14929
Comment #5 by dlang-bot — 2023-02-28T04:49:23Z
dlang/dmd pull request #14929 "Fix 11316: Infer storage class of parameters with function literals" was merged into master: - 9ec4f41e332186154213f939b57f616933086211 by Geod24: Fix 11316: Infer storage class of parameters with function literals This will allow improving functional style code by seamlessly adding `ref` (or `in`) and having the compiler do the job. https://github.com/dlang/dmd/pull/14929