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/internal/types2: predeclared type "comparable" must not be visible before Go 1.18 #46090

Closed
mdempsky opened this issue May 10, 2021 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdempsky
Copy link
Member

This package produces an "undefined: any" error when compiled with go tool compile -G=1:

package p
type _ any

but this package successfully type-checks (but fails later anyway when compiled with -G=3):

package p
type _ comparable

They both produce errors on go2goplay.golang.org.

/cc @griesemer @findleyr

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

griesemer commented Jun 29, 2021

I believe this is working as intended: any may only be used in constraint position (for now, eventually we may make it generally acceptable in place of interface{}). comparable is a predeclared interface type that may be used in types (incl. type declarations); but using a type that is (or embeds) comparable as type for an ordinary variable, or field results in an error.

[edit]: But neither any nor comparable should be accessible for language versions before Go 1.18 (any won't be accessible because one cannot write a constraint before Go 1.18).

@mdempsky
Copy link
Member Author

I think I'm inclined to agree. I'm not sure why I thought type _ comparable should have been invalid, except that go2go rejected it and I must have assumed go/types was actually rejecting it.

Looking more closely at the go2go error diagnostics, I suspect the error message is actually because go2go is generating invalid code in this case. (undefined: comparable looks like a cmd/compile error message, not a go/types one.)

@griesemer griesemer changed the title cmd/compile/internal/types2: "type _ any" rejected but "type _ comparable" accepted cmd/compile/internal/types2: predeclared type "comparable" must not be visible before Go 1.18 Jun 29, 2021
@gopherbot
Copy link

Change https://golang.org/cl/331517 mentions this issue: [dev.typeparams] cmd/compile/internal/types2: "comparable" must not be visible before Go 1.18

@ianlancetaylor
Copy link
Contributor

In case it helps, go2go reports go/types errors with a prefix of "type checking failed for PACKAGE". If you see that message, there is probably a problem with the code being translated. If you don't see that message, it's probably a bug in go2go.

@mdempsky
Copy link
Member Author

@ianlancetaylor Thanks for the tip.

gopherbot pushed a commit that referenced this issue Jul 1, 2021
…e visible before Go 1.18

While at it, clean up the setup of comparable in universe.go.

Fixes #46090

Change-Id: I9655b3e137a03763d677d9a2a730c5570ccff6dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/331517
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@griesemer
Copy link
Contributor

This was fixed by

https://golang.org/cl/331517 in types2
https://golang.org/cl/335032 in go/types

@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

No branches or pull requests

5 participants