Proposals Unofficial Go proposal tracker

Add StrictlyComparable function

#72059 · go/types · low impact · Implemented in Go 1.28 ·

Go has two notions of comparability. A type is comparable if == compiles for it, even if it might panic at run time, as with interfaces. A type is strictly comparable if == never panics. Only strictly comparable types satisfy the comparable constraint in all cases.

An exported type can lose strict comparability without any visible API change, for example by gaining an interface field. That can break callers that use it as a type argument for comparable. go/types exposes Comparable but has no way to check strict comparability, so API-checking tools cannot detect such changes.

The proposal adds types.StrictlyComparable, which reports whether values of a type are strictly comparable as defined by the spec.

func StrictlyComparable(T Type) bool

// Example: a struct with an interface field is comparable but not strictly comparable.
if types.Comparable(t) && !types.StrictlyComparable(t) {
    fmt.Println("== may panic at run time")
}
Proposal
#72059 by kwjw
Status
Implemented on Nov 10, 2026
Release
Go 1.28
Impact
low
Area
go/types