Skip to content

Panic when comparing errors in unexported fields #45

@seveas

Description

@seveas

#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions