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

go/types, types2: misleading error message when type param is not comparable #48712

Closed
findleyr opened this issue Oct 1, 2021 · 2 comments · Fixed by ferrmin/go#261
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Oct 1, 2021

Consider the following invalid program:

package p

func f[T any](t T) func(interface{}) bool {
	return func(x interface{}) bool {
		return x == t
	}
}

The type checker produces the error cannot compare x == t (operator == not defined for interface{}), but that's not accurate. The real problem is that T is not comparable.

CC @griesemer

@findleyr findleyr added this to the Go1.18 milestone Oct 1, 2021
@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 1, 2021
@griesemer griesemer self-assigned this Oct 1, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/372734 mentions this issue: cmd/compile/internal/types2: better error for invalid == on type parameters

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/372894 mentions this issue: go/types, types2: use compiler error message for undefined operators

gopherbot pushed a commit that referenced this issue Dec 17, 2021
For #48712.

Change-Id: I1596fe8688f093e0e92cf5b8d5501aac8631324e
Reviewed-on: https://go-review.googlesource.com/c/go/+/372894
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
Fixes golang#48712.

Change-Id: I6f214cdfdd1815493f2a04828e8f0097f1d8c124
Reviewed-on: https://go-review.googlesource.com/c/go/+/372734
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants