You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: no need to infer type arguments for blank type parameters with any constraint #50547
but blank type parameters can't be used and thus it doesn't matter what their corresponding argument is if the constraint is any (any type will satisfy that constraint). If the constraint is not any we should still infer the type argument so we can verify constraint satisfaction.
Maybe we shouldn't report an error in this case. Or maybe this is so esoteric that is doesn't matter. Filing this issue so we document decision (and perhaps implement it).
In my opinion we shouldn't do anything special for this case, i.e. we should continue to report an error. It doesn't really matter that the type parameter is blank here -- all that really matters is that the function type does not depend on the type parameter.
We could equally well support the following:
funcf[A, Bany](aA) A { returna }
varg=f(0)
Choosing to omit this error for blank type parameters seems somewhat arbitrary. In your proposal, would we support the example here if B were _? If so, that's rather more complex as we'd have to short-circuit inference.
If we omitted the error for the blank-parameter case, then it would be impossible to change the name of the parameter from _ to any other name — even though that kind of renaming should otherwise be completely compatible.
Activity
findleyr commentedon Jan 11, 2022
In my opinion we shouldn't do anything special for this case, i.e. we should continue to report an error. It doesn't really matter that the type parameter is blank here -- all that really matters is that the function type does not depend on the type parameter.
We could equally well support the following:
Choosing to omit this error for blank type parameters seems somewhat arbitrary. In your proposal, would we support the example here if
Bwere_? If so, that's rather more complex as we'd have to short-circuit inference.bcmills commentedon Jan 11, 2022
If we omitted the error for the blank-parameter case, then it would be impossible to change the name of the parameter from
_to any other name — even though that kind of renaming should otherwise be completely compatible.griesemer commentedon Jan 11, 2022
The arguments against not inferring (i.e., for not doing anything special) in this case are convincing. Let's not make any changes. Closing.