Type inference: Understand that T is always implicitly convertible to T? #8564
Unanswered
masonwheeler
asked this question in
Language Ideas
Replies: 1 comment 3 replies
-
Yes. Best way would be to provide a potential spec revision blurb here (you can reference the spec directly, and use things like |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a function with this signature:
public static T? Foo<T>(T? l, T? r) where T : struct, IEqualityOperators<T, T, bool>
Code that invokes it as
Foo(26, 1953)
gives an error:I see no ambiguity here. This should obviously infer the types as
int
. But per discussion on Discord, the type inference engine doesn't understand that because there are no nullable values being provided, and it's not quite smart enough to reason thatT
is always implicitly convertible toT?
.Could this be improved in an upcoming C# version?
Beta Was this translation helpful? Give feedback.
All reactions