Description
Proposal Details
Background
From #56773:
Generics introduced the constraint comparable which denotes the set of all types which are strictly comparable. An API may define an exported type T which may be strictly comparable (see #56548 for terminology) and such a type T may successfully be used as type argument for comparable type parameters elsewhere.
It's possible to change T without visible API change so that it's not strictly comparable anymore.
Whether an exported type is strictly comparable should be considered a part of its API. As such, it would be useful if this property were exposed through go/types
.
Determining whether a type is spec-comparable is exposed via types.Comparable
:
Lines 155 to 158 in b199d97
In the call comparableType(T, true, nil, nil)
, the boolean parameter indicates spec-comparability (true
). Setting this parameter to false
indicates strict comparability.
Proposal
Add the following function to go/types
:
// StrictlyComparable reports whether values of type T are strictly comparable
// (https://go.dev/ref/spec#Comparison_operators).
func StrictlyComparable(T Type) bool {
return comparableType(T, false, nil, nil)
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status