Skip to content

Commit cf4e3e3

Browse files
committed
reflect: explain why convertible or comparable types may still panic
Conversions of slices to arrays may panic since the slice is too short. Comparibility of interfaces may panic since the underlying value is incomparable. This is a follow-up to CL 301652 Change-Id: Ia5d84a6e556a7b82c39add4be93ed7463e63cc8d Reviewed-on: https://go-review.googlesource.com/c/go/+/327589 Trust: Joe Tsai <joetsai@digital-static.net> Trust: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
1 parent 7841cb1 commit cf4e3e3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/reflect/type.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ type Type interface {
107107

108108
// ConvertibleTo reports whether a value of the type is convertible to type u.
109109
// Even if ConvertibleTo returns true, the conversion may still panic.
110+
// For example, a slice of type []T is convertible to *[N]T,
111+
// but the conversion will panic if its length is less than N.
110112
ConvertibleTo(u Type) bool
111113

112114
// Comparable reports whether values of this type are comparable.
113115
// Even if Comparable returns true, the comparison may still panic.
116+
// For example, values of interface type are comparable,
117+
// but the comparison will panic if their dynamic type is not comparable.
114118
Comparable() bool
115119

116120
// Methods applicable only to some types, depending on Kind.

0 commit comments

Comments
 (0)