aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2020-11-12 12:17:33 -0800
committerGitHub <noreply@github.com>2020-11-12 12:17:33 -0800
commitd3c8501c1f408298cf94082d6774e0a5b77c3ce0 (patch)
treee977ecf12af7027bcb2fa5b7ec1062172a623e2c
parentab46b8bd0abd4c4557cc4709ad7ae12d47570603 (diff)
downloadgo-cmp-d3c8501c1f408298cf94082d6774e0a5b77c3ce0.tar.gz
Revert "Adjust for reflect.Type.NumMethod change in Go1.16 (#240)" (#242)
This reverts commit ab46b8bd0abd4c4557cc4709ad7ae12d47570603. The upstream change in Go1.16 has been rolled back. See golang/go#42123
-rw-r--r--cmp/cmpopts/ignore.go3
-rw-r--r--cmp/internal/value/iface.go14
-rw-r--r--cmp/internal/value/iface_test.go35
-rw-r--r--cmp/options.go7
4 files changed, 4 insertions, 55 deletions
diff --git a/cmp/cmpopts/ignore.go b/cmp/cmpopts/ignore.go
index 3cdc211..80c6061 100644
--- a/cmp/cmpopts/ignore.go
+++ b/cmp/cmpopts/ignore.go
@@ -12,7 +12,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/internal/function"
- "github.com/google/go-cmp/cmp/internal/value"
)
// IgnoreFields returns an Option that ignores fields of the
@@ -83,7 +82,7 @@ func newIfaceFilter(ifaces interface{}) (tf ifaceFilter) {
panic("struct cannot have named fields")
case fi.Type.Kind() != reflect.Interface:
panic("embedded field must be an interface type")
- case value.IsEmptyInterface(fi.Type):
+ case fi.Type.NumMethod() == 0:
// This matches everything; why would you ever want this?
panic("cannot ignore empty interface")
default:
diff --git a/cmp/internal/value/iface.go b/cmp/internal/value/iface.go
deleted file mode 100644
index d8d07a9..0000000
--- a/cmp/internal/value/iface.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2020, The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
-
-package value
-
-import "reflect"
-
-var emptyIfaceType = reflect.TypeOf((*interface{})(nil)).Elem()
-
-// IsEmptyInterface reports whether t is an interface type with no methods.
-func IsEmptyInterface(t reflect.Type) bool {
- return t.Kind() == reflect.Interface && emptyIfaceType.Implements(t)
-}
diff --git a/cmp/internal/value/iface_test.go b/cmp/internal/value/iface_test.go
deleted file mode 100644
index 817e1d6..0000000
--- a/cmp/internal/value/iface_test.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2020, The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
-
-package value
-
-import (
- "reflect"
- "testing"
-)
-
-func TestIsEmptyInterface(t *testing.T) {
- type (
- Empty interface{}
- Exported interface{ X() }
- Unexported interface{ x() }
- )
- tests := []struct {
- in reflect.Type
- want bool
- }{
- {reflect.TypeOf((*interface{})(nil)).Elem(), true},
- {reflect.TypeOf((*Empty)(nil)).Elem(), true},
- {reflect.TypeOf((*Exported)(nil)).Elem(), false},
- {reflect.TypeOf((*Unexported)(nil)).Elem(), false},
- {reflect.TypeOf(5), false},
- {reflect.TypeOf(struct{}{}), false},
- }
- for _, tt := range tests {
- got := IsEmptyInterface(tt.in)
- if got != tt.want {
- t.Errorf("IsEmptyInterface(%v) = %v, want %v", tt.in, got, tt.want)
- }
- }
-}
diff --git a/cmp/options.go b/cmp/options.go
index 3b71f54..e57b9eb 100644
--- a/cmp/options.go
+++ b/cmp/options.go
@@ -11,7 +11,6 @@ import (
"strings"
"github.com/google/go-cmp/cmp/internal/function"
- "github.com/google/go-cmp/cmp/internal/value"
)
// Option configures for specific behavior of Equal and Diff. In particular,
@@ -162,7 +161,7 @@ func FilterValues(f interface{}, opt Option) Option {
}
if opt := normalizeOption(opt); opt != nil {
vf := &valuesFilter{fnc: v, opt: opt}
- if ti := v.Type().In(0); !value.IsEmptyInterface(ti) {
+ if ti := v.Type().In(0); ti.Kind() != reflect.Interface || ti.NumMethod() > 0 {
vf.typ = ti
}
return vf
@@ -287,7 +286,7 @@ func Transformer(name string, f interface{}) Option {
panic(fmt.Sprintf("invalid name: %q", name))
}
tr := &transformer{name: name, fnc: reflect.ValueOf(f)}
- if ti := v.Type().In(0); !value.IsEmptyInterface(ti) {
+ if ti := v.Type().In(0); ti.Kind() != reflect.Interface || ti.NumMethod() > 0 {
tr.typ = ti
}
return tr
@@ -346,7 +345,7 @@ func Comparer(f interface{}) Option {
panic(fmt.Sprintf("invalid comparer function: %T", f))
}
cm := &comparer{fnc: v}
- if ti := v.Type().In(0); !value.IsEmptyInterface(ti) {
+ if ti := v.Type().In(0); ti.Kind() != reflect.Interface || ti.NumMethod() > 0 {
cm.typ = ti
}
return cm