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

Panic when comparing errors in unexported fields #45

Closed
seveas opened this issue Jul 23, 2020 · 3 comments
Closed

Panic when comparing errors in unexported fields #45

seveas opened this issue Jul 23, 2020 · 3 comments

Comments

@seveas
Copy link

seveas commented Jul 23, 2020

#33 broke the comparison of structs with errors in an unexported fields. THis code used to work just fine with deep 1.0.4, but panics with 1.0.7:

package main

import (
	"fmt"
	"github.com/go-test/deep"
)

type foo struct {
	bar error
}

func main() {
	deep.CompareUnexportedFields = true
	e1 := foo{bar: fmt.Errorf("error")}
	e2 := foo{bar: fmt.Errorf("error")}
	deep.Equal(e1, e2)
}

The panic:

$ go run deep_panic.go
panic: reflect: reflect.flag.mustBeExported using value obtained using unexported field

goroutine 1 [running]:
reflect.flag.mustBeExportedSlow(0x2b3)
	/usr/local/Cellar/go/1.14.3/libexec/src/reflect/value.go:225 +0x12e
reflect.flag.mustBeExported(...)
	/usr/local/Cellar/go/1.14.3/libexec/src/reflect/value.go:216
reflect.Value.Call(0x10e1ca0, 0xc00008e230, 0x2b3, 0x0, 0x0, 0x0, 0xc00008e230, 0x2b3, 0x0)
	/usr/local/Cellar/go/1.14.3/libexec/src/reflect/value.go:320 +0x4d
github.com/go-test/deep.(*cmp).equals(0xc00009aeb0, 0x10e1ca0, 0xc00008e230, 0xb4, 0x10e1ca0, 0xc00008e240, 0xb4, 0x1)
	/Users/seveas/go/pkg/mod/github.com/go-test/deep@v1.0.7/deep.go:145 +0x335b
github.com/go-test/deep.(*cmp).equals(0xc00009aeb0, 0x10e3040, 0xc00008e230, 0x99, 0x10e3040, 0xc00008e240, 0x99, 0x0)
	/Users/seveas/go/pkg/mod/github.com/go-test/deep@v1.0.7/deep.go:223 +0x246c
github.com/go-test/deep.Equal(0x10e3040, 0xc00008e230, 0x10e3040, 0xc00008e240, 0x0, 0x11203e0, 0xc00008e220)
	/Users/seveas/go/pkg/mod/github.com/go-test/deep@v1.0.7/deep.go:88 +0x2b4
main.main()
	/Users/seveas/code/katyusha/deep_panic.go:16 +0x118
exit status 2
seveas added a commit to seveas/herd that referenced this issue Jul 24, 2020
Unfortunately this runs into a regression in deep, filed as
go-test/deep#45. But given that we don't
actually *use* the errors field anywhere, just comment it out for now to
work around that bug.
seveas added a commit to seveas/herd that referenced this issue Mar 10, 2022
Unfortunately this runs into a regression in deep, filed as
go-test/deep#45. But given that we don't
actually *use* the errors field anywhere, just comment it out for now to
work around that bug.
@daniel-nichter
Copy link
Member

Sorry for slow response, but fixed in #54 and will be released this week or next.

@daniel-nichter
Copy link
Member

@seveas
Copy link
Author

seveas commented Dec 12, 2022

Better slow than never, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants