-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: type inference should look inside type parameters #49575
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
Comments
Thank you very much for raising this question. package p
type SC[E any] interface {
[]E
}
func F[E any, SE SC[E]] (x SE) {
}
func WarpF[E any, SE SC[E]] (x SE) {
F(x)
} or package p
func F[E any, SE []E] (x SE) {
}
func WarpF[E any, SE []E] (x SE) {
F(x)
} |
I don't see anything in the current constraint type inference algorithm that would permit this kind of type inference. This is easier to discuss if we don't use the same names for the different type parameters. package p
func f[FT any, FPT *FT](x FPT) {}
func _[GT any, GPT *GT](x GPT) {
f(x)
} In the call The suggestion in this issue is presumably something like: when unifying a type argument I don't see any immediate problem with that. However, my personal feeling is that we should not add any more type inference rules for 1.18. Type inference is already very complex and subtle. Let's see where we are before we start making it more complicated. It is always possible to write f[GT, GPT](x) That is very clear. Let's be very careful to make sure that we don't add further type inference rules at the cost of code reading clarity. |
I agree with @ianlancetaylor that we should not make type inference more complex for 1.18, without gaining experience with it. I'm going to move this to 1.19; and even then, we will need to make a decision about this. |
Can we please use this issue or #49800 to improve the error message for Go 1.18? Currently the error message points to the callee instead the call location, and the message is non-obvious. Fixing code under the current inference rules should be fairly trivial with a good error message. |
It looks this works on 1.18 branch tip now. |
This is extracted from issue #49441.
For
we currently get an error (at the wrong line, see issue #45985 for that).
But the question arises, should we be able to infer the type arguments in this case?
@hanchaoqun has provided CL 362776 (thanks!) that addresses this and would make this code work.
Need to decide a) if we want this; and b) is the CL correct (are there unintended consequences).
cc @ianlancetaylor for thoughts on this.
The text was updated successfully, but these errors were encountered: