Skip to content
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

cmd/compile: "cannot infer U" for 2D generic constraints #68320

Closed
karalabe opened this issue Jul 5, 2024 · 2 comments
Closed

cmd/compile: "cannot infer U" for 2D generic constraints #68320

karalabe opened this issue Jul 5, 2024 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@karalabe
Copy link
Contributor

karalabe commented Jul 5, 2024

Go version

latest

Output of go env in your module/workspace:

doens't matter

What did you do?

Defined a 2D type constraint and tried to call a method with it.

type array interface {
	~[20]byte | ~[32]byte
}
type matrix[U array] interface {
	~[2]U | ~[3]U
}

func F[T matrix[U], U array](v T) {
	fmt.Println(v)
}

https://go.dev/play/p/zEAITslJw5Y

What did you see happen?

The compiler cannot deduce the type of U.

What did you expect to see?

I expect both lines to work, the type information is there for the compiler to figure out both T and U.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 5, 2024
@gabyhelp
Copy link

gabyhelp commented Jul 5, 2024

@karalabe
Copy link
Contributor Author

karalabe commented Jul 5, 2024

Lol, already had a similar issue closed, just that one also has unbounded slices in there vs this one only arrays. Sigh.

@karalabe karalabe closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

3 participants