-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: misleading compiler error #51233
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
There is no form of type inference that will figure out the additional type argument for That said I agree that the error message is pretty bad. |
@ianlancetaylor something that's a bit confusing about this is that it only seems to be a compile error when I actually call Is this expected behavior? It's a bit weird to me that changing something outside of the struct definition can magically cause a compilation error in a struct definition that hasn't changed. |
I just looked at this briefly. It looks like the bug is in the order of instantiation: where we try to substitute in the underlying of The error is not coming from type inference, which is why it only occurs if the field is used. |
Change https://go.dev/cl/387918 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
https://go.dev/play/p/PzbJGM7V9dn?v=gotip
What did you expect to see?
Nothing.
What did you see instead?
If I change the line from the red version to the green version (adding the explicit type), then the compilation error disappears. I expected the compiler to figure out
RG
since it was part of the definition ofRCT
.If type inference isn't able to figure this out, then it would be good to fix the compiler error to be less confusing.
makeFn
is a function, the error is actually that the compiler can't infer how to instantiate it.Notes
The text was updated successfully, but these errors were encountered: