-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: spec: permit unused type parameters to not be inferred #57620
Comments
I think there are actually two issues that you (or, at least, your code sample) might be conflating here:
The former might get addressed by #58650. The severity of the latter (about which the title of this proposal seems to be) can be reduced by shifting some of the type parameters around. I'm doubtful a general solution in the inference algorithm is reasonably possible. Also, the OP playground code uses an interface type switch, which is evaluated at runtime and would require |
I agree that there are (at least) two issues here:
Regarding 1), which the proposal title is about: I don't have a good use case where one would want to specify a type parameter that is never used (as opposed to only used depending on the types of other type parameters), but in the former case, such type parameters could be named Ignoring type parameters depending on the value of other type arguments (or the code in a function body) most likely is not something we're going to take on. Regarding 2): I think that requires a separate, independent proposal. |
Regarding 1) above: I don't think we should do this. |
I don't have the bandwidth nor will to create a second proposal, this isn't the most important to me. Thanks for the consideration, though. I'll close this proposal. |
I was recently trying roughly the following segment of code expecting it to work:
https://go.dev/play/p/yTVhxJ82pMR
Lines 47 and 48 are commented out; lines 53 and 54 are what I would have to do if I want to use
First
. If possible, it'd be great to not have to fully specify the types and instead rely entirely on type inference.Speaking as a complete newbie / uninformed person here, I'd think the algorithm would be:
For slices,
For maps,
I recognize this is a naive and simple proposal that absolutely does not capture the underlying complexity. Go also currently requires all types to be specified, and in the slice case, there is no
K
; this requirement would need to be relaxed in the type union case.The closest related issue I see is #56975, but that is different because the proposal is specific to functions and is actually not about a union.
The text was updated successfully, but these errors were encountered: