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

Should this not be inferable? #7096

Closed
leppie opened this issue Nov 28, 2015 · 2 comments
Closed

Should this not be inferable? #7096

leppie opened this issue Nov 28, 2015 · 2 comments

Comments

@leppie
Copy link
Contributor

leppie commented Nov 28, 2015

using System;
class p
{
    static T Baz<T>(T t) => t;
    static Func<T, T> Get<T>() => Baz;
    static void Ork<T>(Func<T, T> f)  {  }
    static void Main() 
    {
        Ork<string>(Get()); // cant resolve arg
        Ork<string>(Baz); // this is fine
    }
}
@HaloFour
Copy link

That would require #5429, C# doesn't infer generic type arguments based on the expected target type. Get would need to accept an argument that was either of type T or of Func<T> which would be used by the compiler to infer the generic type arguments:

static Func<T, T> Get<T>(T value) => Baz;
...
Ork<string>(Get("foo"));

@leppie
Copy link
Contributor Author

leppie commented Nov 29, 2015

@HaloFour Same your linked issue. Closing.

@leppie leppie closed this as completed Nov 29, 2015
@gafter gafter removed the Discussion label Nov 29, 2015
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

3 participants