Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
@agocke is investigating extending type inference to take constraints into account. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@kingces95 commented on Thu Apr 20 2017
Given:
Expected Behavior: Compiler is able to infer type arguments for
Method
as<Foo<int>, int>
.Actual Behavior: Compiler generates an error; Compiler is unable to infer type arguments.
Whenever a generic argument (e.g.
TFoo
) has astruct
constraint (e.g.TFoo : struct
) and a struct is passed as an argument for that parameter (e.g.Foo<int>
) than the generic argument necessarily must be of the struct type (e.g.Foo<int>
) (this works; compiler infers correctly in this case). If the same generic argument withstruct
constraint also has an interface constraint containing other generic arguments (e.g.TFoo : struct, IFoo<T>
) and the struct argument implements one version of that interface (e.g.Foo<int> : IFoo<int>
) then those other generic arguments (e.g.T
) must assume the types of the struct argument interface instantiation (e.g.int
).@gafter commented on Fri Apr 21 2017
This is a language feature request. Moving to the csharplang repo.
Beta Was this translation helpful? Give feedback.
All reactions