-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: "cannot infer T" in Go 1.21 (regression from Go 1.20) #63873
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
/cc @golang/compiler |
(attn @griesemer) |
This was a bug that was fixed for Go 1.21. The type parameter More concretely, here's a slightly modified version of your example: func main() {
var v Foo[int]
var y uint
checkMatch(v, y)
}
func checkMatch[T Integer](v Foo[T], s T) {} This code correctly infers For the original discussion see #60377. Closing as working as intended. |
Right, I see. Apart from the assert, I used the type parameter to instantiate the right version of whatever was using My specific use case was a method on Here is a simplified version of what I'm doing: https://go.dev/play/p/PXuOVTqWMmZ Anyway, I guess I'll have to add methods with the actual requested type (basically, giving the parameter to |
As you say, you could add a dummy method (playground). (I suppose one could try to make it work for both cases, but that would probably be complicated to explain.) |
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?
Run this program: https://go.dev/play/p/jx329NFz7ZU
What did you expect to see?
It compiles.
What did you see instead?
It fails to compile in Go 1.21, while it still compiled in Go 1.20.
Go 1.21 error message:
I have code like this as an assert to verify that
v
(in the main function) is of a particular type.The text was updated successfully, but these errors were encountered: