Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need LDM decisions for overload resolution in the face of 'out var' #13845

Closed
gafter opened this issue Sep 15, 2016 · 4 comments
Closed

Need LDM decisions for overload resolution in the face of 'out var' #13845

gafter opened this issue Sep 15, 2016 · 4 comments

Comments

@gafter
Copy link
Member

gafter commented Sep 15, 2016

We need the LDM to decide how 'out var' should interact with overload resolution. Currently, the presence of an out var argument prevents that parameter position from contributing to betterness. For example, the following program is ambiguous in the current prototype.

I would recommend saying that there is an implicit "conversion from expression" from the 'out var' to any (out) argument type. Then, the usual tie-breakers will cause the first of these methods to be selected.

class Program
{
    static void Main(string[] args)
    {
        M(out var t); // error: ambiguous?
    }
    static void M(out string s)
    {
        s = null;
    }
    static void M(out object o)
    {
        o = null;
    }
}
@gafter
Copy link
Member Author

gafter commented Sep 15, 2016

/cc @AlekseyTs FYI

@gafter
Copy link
Member Author

gafter commented Sep 15, 2016

The draft spec for "out var" says

For the purposes of overload resolution (see sections 7.5.3.2 Better function member and 7.5.3.3 Better conversion from expression), neither conversion is considered better when corresponding argument is an implicitly-typed out variable declaration.

This appears to be intended to override the parts of the current specification that compare only the method parameters, and ignore the argument and its conversions, such as

• Otherwise, if MP has more specific parameter types than MQ, then MP is better than MQ.

@gafter
Copy link
Member Author

gafter commented Sep 28, 2016

The specification in https://github.com/dotnet/roslyn/blob/master/docs/features/outvar.md has been updated in 2891628 to align with the intent of the LDM and the shape of the implementation.

@gafter gafter closed this as completed Sep 28, 2016
@gafter
Copy link
Member Author

gafter commented Sep 28, 2016

The draft has been updated in #13999. I checked with @MadsTorgersen and the LDM does not intend to produce any further specification text for quite some time. He is OK with a spec that aligns with the implementation, the shape of the current specification, and the intent of the LDM as previously expressed. So there is nothing more to do here until it is time to integrate this into the full specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant