✅ Generic Binding Func<...> when you have inner generics is giving me "cannot infer types"
Been banging my head against this one for awhile now, I just cant seem to get the type inference to work right.
So as an example I have this code that demonstrates the issue:
The issue occurs on this line:
This one gives me the usual error:
The type arguments for method 'Routing.TestInferArg<TChild>(Func<Routing.TestParent<TChild>, Unit>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. [CS0411]Note: this line does not give any error I assume this happens because Func is declared as such? Namely, that
in T
messes with the type inference of a nested type, whereas out TResult
is why it can succeed in infering it?
Anyone know an approach to deal with this?1 Reply
Hmm, even tried doing this:
And then modified
TestInferArg
as such
And it still just cant seem to handle infering the type when its specifically an arg. It handles the return type of the function just fine, bleh
Lol even this cant infer the type? wat?
I woulda that that for sure would work, since the return type specifies TChild
is an int now, I dunno why the compiler cant at least figure this one out now
Declaring it this way also doesnt work
Even this most minimalist example shows how it just cannot seem to infer it, blegh
That's cuz an anonymous function is already a Func<...>
so the types match now
Whereas a method has to be converted to a Func which I guess makes the compiler fail to figure it out?