-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: constraint type inference for generic types is not implemented #54469
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
Title format was not really clear for me, so I apologize for the inappropriate title. |
To be honest struct was not meant in docs, but I found out, that type inference for structs does not work too |
In Go 1.19 constraint type inference only applies to functions, not types. See https://go.dev/cl/404875. We can leave this issue open as a request to try to make this work in the future. |
Thanks for the reply. I think if this is implemented it will be much more logical than type inference only for functions. Most likely I will try to do this myself, I am already reading the guideline. |
It turns out that type inference for types is much more difficult than type inference for functions. A function is not a type and thus cannot be used to instantiate another function or type (nor does it need to be inferred). But a type may be used to instantiate another type, and possibly itself. On top of that, if we combine this with type inference, there are all kinds of cycle problems that we currently can't handle correctly (and don't fully understand), and which may require significant (re-)engineering of the type checker. And it's not even clear that it's desirable as it may make code really difficult to read. |
We don't plan to do this. Closing. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/e4HeQf10djz
What did you expect to see?
According to https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#pointer-method-example
I expected to see that constraint type inference will work for function type definitions too/
What did you see instead?
Constraint type inference does not work for type definitions where type is some function/
The text was updated successfully, but these errors were encountered: