Discussion: Type inference workflow can be confusing for static member in generic type #6605
Replies: 2 comments
-
This is really a consequence of the pit of failure you can get into with wildcard generics. Note that explicitly using the type parameter in the I'm not sure if this is a beginner problem; wildcard generic type arguments are kind of an advanced feature that I doubt too many people really use. I personally try to avoid them since I don't like trying to predict if I'm going to end up with a value restriction somewhere. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback @cartermp, it makes sense that using I was missing type annotation on This may be very limitied use case not worth considering in context of compiler, but really looking to see if other people are also hiting this and if there are ideas how to make the compiler more helpful troubleshooting this. |
Beta Was this translation helpful? Give feedback.
-
Repro steps
I have hit this one several times:
Initially forgetting type annotation on the static member.
I think this is painful for newcomers and a reasonably annoying issue for more seasoned users.
I understand the reason the tooling type inference would pick up
int
in this case, despite the compiled type ofRec<'T>.Empty
is always going to beRec<obj>
.My main issue is that, at no point in my workflow, have I seen a warning on the
Empty
member declaration.Actual behavior
Expected behavior
I'd like to figure out a way to get a warning to show up there as early as possible, maybe a check on specific or more generic cases can be added that would spawn such warning.
One issue is that it would be a breaking change when code uses implicit/inferred fallback to
obj
and maybe other cases where type inference will pick a single instantiation.Ideas for checks:
specific one:
generic one:
would those checks be sound? other ideas?
Note:
Known workarounds
Hit the issue frequently enough in a row to not hit it for a while
Related information
Win10/VS2019
Beta Was this translation helpful? Give feedback.
All reactions