Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop hacks to work around Go reflection bugs in Go1.9 #282

Merged
merged 1 commit into from Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 0 additions & 17 deletions cmp/compare.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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]
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions cmp/compare_test.go
Expand Up @@ -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{},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 0 additions & 10 deletions cmp/internal/flags/toolchain_legacy.go

This file was deleted.

10 changes: 0 additions & 10 deletions cmp/internal/flags/toolchain_recent.go

This file was deleted.