D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12830 - Missed ref/out inference for delegate arguments
Summary: Missed ref/out inference for delegate arguments
Status: RESOLVED DUPLICATE of issue 9423
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P1 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-05-31 20:28 UTC by bearophile_hugs
Modified: 2020-08-26 17:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-05-31 20:28:49 UTC
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 Mathias LANG 2020-08-26 17:27:59 UTC
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 ***