Kind(-1).String() used to panic; let's not.
Change-Id: I1dfc0e3298beb37d77713d8327579bbde90dd156
Reviewed-on: https://go-review.googlesource.com/c/go/+/393015
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
t.Errorf("name of type parameter mismatched, want:%s, got:%s", want2, got)
}
}
+
+func TestNegativeKindString(t *testing.T) {
+ x := -1
+ s := Kind(x).String()
+ want := "kind-1"
+ if s != want {
+ t.Fatalf("Kind(-1).String() = %q, want %q", s, want)
+ }
+}
// String returns the name of k.
func (k Kind) String() string {
- if int(k) < len(kindNames) {
- return kindNames[k]
+ if uint(k) < uint(len(kindNames)) {
+ return kindNames[uint(k)]
}
return "kind" + strconv.Itoa(int(k))
}