]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: explain why convertible or comparable types may still panic
authorJoe Tsai <joetsai@digital-static.net>
Sat, 12 Jun 2021 19:25:12 +0000 (12:25 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Tue, 15 Jun 2021 00:14:03 +0000 (00:14 +0000)
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>
src/reflect/type.go

index 39414fc2a642d0e8f71d51f7a366fc50848b10ab..df863ae106f487e635773a36cbb888ca5fb07dc1 100644 (file)
@@ -107,10 +107,14 @@ type Type interface {
 
        // ConvertibleTo reports whether a value of the type is convertible to type u.
        // Even if ConvertibleTo returns true, the conversion may still panic.
+       // For example, a slice of type []T is convertible to *[N]T,
+       // but the conversion will panic if its length is less than N.
        ConvertibleTo(u Type) bool
 
        // Comparable reports whether values of this type are comparable.
        // Even if Comparable returns true, the comparison may still panic.
+       // For example, values of interface type are comparable,
+       // but the comparison will panic if their dynamic type is not comparable.
        Comparable() bool
 
        // Methods applicable only to some types, depending on Kind.