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

builtin: update documentation of comparable #51083

Closed
fzipp opened this issue Feb 8, 2022 · 1 comment
Closed

builtin: update documentation of comparable #51083

fzipp opened this issue Feb 8, 2022 · 1 comment

Comments

@fzipp
Copy link
Contributor

fzipp commented Feb 8, 2022

  1. The declaration of comparable in builtin should reflect the decision that its underlying type is not itself (see spec: document definition of comparable #50791):
-type comparable comparable
+type comparable interface{ comparable }
  1. The doc comment lists interfaces as comparable:

implemented by all comparable types (booleans, numbers, strings, pointers, channels, interfaces, arrays of comparable types, structs whose fields are all comparable types).

However, according to the spec not all interfaces implement comparable:

a type T implements comparable if:

  • T is not an interface type and T supports the operations == and !=; or
  • T is an interface type and each type in T's type set implements comparable.

Even though interfaces that are not type parameters can be compared (possibly causing a run-time panic) they do not implement comparable.

Maybe the doc comment should be more precise.

What version of Go are you using (go version)?

$ go version
go version devel go1.18-9e0de1fe7b Tue Feb 8 19:03:52 2022 +0000 darwin/arm64
@gopherbot
Copy link

Change https://go.dev/cl/384235 mentions this issue: builtin: clarify that interface types do not implement comparable

@golang golang locked and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants