aboutsummaryrefslogtreecommitdiff
path: root/cmp
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2017-07-12 01:21:05 -0600
committerGitHub <noreply@github.com>2017-07-12 01:21:05 -0600
commitd82a57591e220ab549b0901ee5c6ae024077fc64 (patch)
treeededa2faf9247b96e35135d68e28397e39e8fb95 /cmp
parent5c2f3415b05eca653272685cb8b1fdf4acfb6cd6 (diff)
downloadgo-cmp-d82a57591e220ab549b0901ee5c6ae024077fc64.tar.gz
Make lack of support for AllowUnexported more obvious (#4)
Rather than waiting until the unsafeRetrieveField helper function is actually called, panic at the moment someone tries to use AllowUnexported to make the failure more obvious.
Diffstat (limited to 'cmp')
-rw-r--r--cmp/options.go3
-rw-r--r--cmp/unsafe_panic.go4
-rw-r--r--cmp/unsafe_reflect.go2
3 files changed, 8 insertions, 1 deletions
diff --git a/cmp/options.go b/cmp/options.go
index f69a066..ec176c7 100644
--- a/cmp/options.go
+++ b/cmp/options.go
@@ -262,6 +262,9 @@ type comparer struct {
//
// NOTE: This feature is experimental and may be removed!
func AllowUnexported(types ...interface{}) Option {
+ if !supportAllowUnexported {
+ panic("AllowUnexported is not supported on App Engine Classic or GopherJS")
+ }
m := make(map[reflect.Type]bool)
for _, typ := range types {
t := reflect.TypeOf(typ)
diff --git a/cmp/unsafe_panic.go b/cmp/unsafe_panic.go
index 79e8aaa..0d44987 100644
--- a/cmp/unsafe_panic.go
+++ b/cmp/unsafe_panic.go
@@ -8,6 +8,8 @@ package cmp
import "reflect"
+const supportAllowUnexported = false
+
func unsafeRetrieveField(reflect.Value, reflect.StructField) reflect.Value {
- panic("unsafeRetrieveField is not implemented on appengine or gopherjs")
+ panic("unsafeRetrieveField is not implemented")
}
diff --git a/cmp/unsafe_reflect.go b/cmp/unsafe_reflect.go
index 4b04bca..81fb826 100644
--- a/cmp/unsafe_reflect.go
+++ b/cmp/unsafe_reflect.go
@@ -11,6 +11,8 @@ import (
"unsafe"
)
+const supportAllowUnexported = true
+
// unsafeRetrieveField uses unsafe to forcibly retrieve any field from a struct
// such that the value has read-write permissions.
//