aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2021-12-07 13:01:18 -0800
committerGitHub <noreply@github.com>2021-12-07 13:01:18 -0800
commit3242228551a7556abc624443ef03a6dbfeeacd22 (patch)
treebe5bceb63176bfcd525b25b0aaf7f1126b4e0810
parentf59cd61478ea347f01124caa5fe7cafe512a4c8f (diff)
downloadgo-cmp-3242228551a7556abc624443ef03a6dbfeeacd22.tar.gz
Drop hacks to work around Go reflection bugs in Go1.9 (#282)
Now that Go 1.11 is the minimally supported version, we can drop some local hacks to work around bugs in reflect that were present in Go1.9.
-rw-r--r--cmp/compare.go17
-rw-r--r--cmp/compare_test.go14
-rw-r--r--cmp/internal/flags/toolchain_legacy.go10
-rw-r--r--cmp/internal/flags/toolchain_recent.go10
4 files changed, 2 insertions, 49 deletions
diff --git a/cmp/compare.go b/cmp/compare.go
index 86d0903..2a54467 100644
--- a/cmp/compare.go
+++ b/cmp/compare.go
@@ -36,7 +36,6 @@ import (
"strings"
"github.com/google/go-cmp/cmp/internal/diff"
- "github.com/google/go-cmp/cmp/internal/flags"
"github.com/google/go-cmp/cmp/internal/function"
"github.com/google/go-cmp/cmp/internal/value"
)
@@ -319,7 +318,6 @@ func (s *state) tryMethod(t reflect.Type, vx, vy reflect.Value) bool {
}
func (s *state) callTRFunc(f, v reflect.Value, step Transform) reflect.Value {
- v = sanitizeValue(v, f.Type().In(0))
if !s.dynChecker.Next() {
return f.Call([]reflect.Value{v})[0]
}
@@ -343,8 +341,6 @@ func (s *state) callTRFunc(f, v reflect.Value, step Transform) reflect.Value {
}
func (s *state) callTTBFunc(f, x, y reflect.Value) bool {
- x = sanitizeValue(x, f.Type().In(0))
- y = sanitizeValue(y, f.Type().In(1))
if !s.dynChecker.Next() {
return f.Call([]reflect.Value{x, y})[0].Bool()
}
@@ -372,19 +368,6 @@ func detectRaces(c chan<- reflect.Value, f reflect.Value, vs ...reflect.Value) {
ret = f.Call(vs)[0]
}
-// sanitizeValue converts nil interfaces of type T to those of type R,
-// assuming that T is assignable to R.
-// Otherwise, it returns the input value as is.
-func sanitizeValue(v reflect.Value, t reflect.Type) reflect.Value {
- // TODO(≥go1.10): Workaround for reflect bug (https://golang.org/issue/22143).
- if !flags.AtLeastGo110 {
- if v.Kind() == reflect.Interface && v.IsNil() && v.Type() != t {
- return reflect.New(t).Elem()
- }
- }
- return v
-}
-
func (s *state) compareStruct(t reflect.Type, vx, vy reflect.Value) {
var addr bool
var vax, vay reflect.Value // Addressable versions of vx and vy
diff --git a/cmp/compare_test.go b/cmp/compare_test.go
index c7a409d..9ad9456 100644
--- a/cmp/compare_test.go
+++ b/cmp/compare_test.go
@@ -1447,14 +1447,6 @@ func embeddedTests() []test {
return s
}
- // TODO(≥go1.10): Workaround for reflect bug (https://golang.org/issue/21122).
- wantPanicNotGo110 := func(s string) string {
- if !flags.AtLeastGo110 {
- return ""
- }
- return s
- }
-
return []test{{
label: label + "/ParentStructA/PanicUnexported1",
x: ts.ParentStructA{},
@@ -1745,8 +1737,7 @@ func embeddedTests() []test {
label: label + "/ParentStructG/PanicUnexported1",
x: ts.ParentStructG{},
y: ts.ParentStructG{},
- wantPanic: wantPanicNotGo110("cannot handle unexported field"),
- wantEqual: !flags.AtLeastGo110,
+ wantPanic: "cannot handle unexported field",
reason: "ParentStructG has unexported fields",
}, {
label: label + "/ParentStructG/Ignored",
@@ -1836,8 +1827,7 @@ func embeddedTests() []test {
label: label + "/ParentStructI/PanicUnexported1",
x: ts.ParentStructI{},
y: ts.ParentStructI{},
- wantPanic: wantPanicNotGo110("cannot handle unexported field"),
- wantEqual: !flags.AtLeastGo110,
+ wantPanic: "cannot handle unexported field",
reason: "ParentStructI has unexported fields",
}, {
label: label + "/ParentStructI/Ignored1",
diff --git a/cmp/internal/flags/toolchain_legacy.go b/cmp/internal/flags/toolchain_legacy.go
deleted file mode 100644
index 82d1d7f..0000000
--- a/cmp/internal/flags/toolchain_legacy.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2019, 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 file.
-
-// +build !go1.10
-
-package flags
-
-// AtLeastGo110 reports whether the Go toolchain is at least Go 1.10.
-const AtLeastGo110 = false
diff --git a/cmp/internal/flags/toolchain_recent.go b/cmp/internal/flags/toolchain_recent.go
deleted file mode 100644
index 8646f05..0000000
--- a/cmp/internal/flags/toolchain_recent.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2019, 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 file.
-
-// +build go1.10
-
-package flags
-
-// AtLeastGo110 reports whether the Go toolchain is at least Go 1.10.
-const AtLeastGo110 = true