Skip to content

cmp: top-level interfaces are not matched #88

@dsnet

Description

@dsnet

Consider the following:

equalErrors := cmp.Comparer(func(_, _ error) bool { return true })

cmp.Equal(io.EOF, &os.PathError{}, equalErrors) // false

type E struct{ E error }
cmp.Equal(E{io.EOF}, E{&os.PathError{}}, equalErrors) // true

Note that the first comparison always reports false, while the later reports true. The reason is because reflect.ValueOf on an interface loses information about the fact that the value passed in is an interface. Thus, the first call to cmp.Equal reports false because the underlying types are not equal, before even giving the custom Comparer passed in a chance to apply.

We should probably box the top-level values into an empty interface to fix this.

\cc @neild

Metadata

Metadata

Assignees

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