Comparing contravariant types doesn't work as expected using Transformer
Open
question
- Dominant language
- Go
- Stars
- 4.7k
- Forks
- 243
- PR merge metrics
- No merged PRs in 30d
Description
```
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
)
type intHolder struct {
i int
}
func main() {
got := []intHolder{
{i: 1},
}
want := []int{1}
fmt.Println(cmp.Diff(want, got, cmp.Transformer("myTransformer", func(h intHolder) int {
return h.i
})))
}
```
produces:
```
interface{}(
- []int{1},
+ []main.intHolder{{i: 1}},
)
```
https://play.golang.org/p/GQqAZmbYUD8
Digging into the implementation revealed effectively that Transform is _skipped_ whenever the types being compared aren't identical.
The same thing happens when `got` and `want` are scalars rather than slices: https://play.golang.org/p/r2O2UKYRD-r
Contributor guide
Assessment
This issue has not been assessed yet.