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: puzzling "does not satisfy comparable" error message #49112

Open
ALTree opened this issue Oct 22, 2021 · 2 comments
Open

cmd/compile: puzzling "does not satisfy comparable" error message #49112

ALTree opened this issue Oct 22, 2021 · 2 comments

Comments

@ALTree
Copy link
Member

@ALTree ALTree commented Oct 22, 2021

$ gotip version
go version devel go1.18-9ff91b9098 Fri Oct 22 00:57:18 2021 +0000 windows/amd64
package main

type I interface {
	int
}

func f[G I](g G) {
	println(g)
}

func main() {
	var v1 float64
	var v2 []int
	f(v1)
	f(v2)
}

Building prints:

$ gotip build test.go
# command-line-arguments
.\test.go:14:3: float64 does not satisfy I
.\test.go:15:3: []int does not satisfy comparable

The error message for f(v1) makes sense:

float64 does not satisfy I

but the one for f(v2) is puzzling:

[]int does not satisfy comparable

It mentions the predeclared constraint comparable, but comparable has nothing to do with I. Why?

cc @griesemer @findleyr

@ALTree ALTree added this to the Go1.18 milestone Oct 22, 2021
@DiscoRiver
Copy link

@DiscoRiver DiscoRiver commented Oct 22, 2021

Error message needs updating?

return errorf("%s does not satisfy comparable", targ)

Loading

@findleyr
Copy link
Contributor

@findleyr findleyr commented Oct 22, 2021

@DiscoRiver yes, that looks right. We're checking comparable as a precondition (since the type set {int} is comparable), but the error message is misleading.

Thanks for the report.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants