Bug 12830 – Missed ref/out inference for delegate arguments
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-05-31T20:28:49Z
Last change time
2020-08-26T17:27:59Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-05-31T20:28:49Z
I am not sure, but perhaps all the following code should compile:
void main() {
void function(int x) f1;
f1 = (x) {}; // OK
void function(ref int x) f2;
f2 = (ref int x) {}; // OK
f2 = (ref x) {}; // OK
f2 = (x) {}; // Error
void function(out int x) f3;
f3 = (out int x) {}; // OK
f3 = (out x) {}; // OK
f3 = (x) {}; // Error
void delegate(int x) d1;
d1 = (x) {}; // OK
void delegate(ref int x) d2;
d2 = (ref int x) {}; // OK
d2 = (ref x) {}; // OK
d2 = (x) {}; // Error
void delegate(out int x) d3;
d3 = (out int x) {}; // OK
d3 = (out x) {}; // OK
d3 = (x) {}; // Error
}
DMD 2.066alpha gives:
test.d(7,10): Error: cannot implicitly convert expression (__lambda4) of type void function(int x) pure nothrow @nogc @safe to void function(ref int x)
test.d(11,10): Error: cannot implicitly convert expression (__lambda7) of type void function(int x) pure nothrow @nogc @safe to void function(out int x)
test.d(17,10): Error: cannot implicitly convert expression (__lambda11) of type void delegate(int x) pure nothrow @nogc @safe to void delegate(ref int x)
test.d(21,10): Error: cannot implicitly convert expression (__lambda14) of type void delegate(int x) pure nothrow @nogc @safe to void delegate(out int x)
Comment #1 by pro.mathias.lang — 2020-08-26T17:27:59Z
This is a duplicate of 9423, which contains more information, including a comment from Kenji as to why this is the case.
*** This issue has been marked as a duplicate of issue 9423 ***