Skip to content

builtin: update documentation of comparable #51083

@fzipp

Description

@fzipp
  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions