Open ycydsxy opened 3 years ago
I think that's a bug for golang. When I use 1.16.6 compiler, stack overflow happened. But I use 1.17rc1 compiler, It works fine.
go 1.16.6 reflect/type.go:1590 does not check package path.
func haveIdenticalType(T, V Type, cmpTags bool) bool {
if cmpTags {
return T == V
}
if T.Name() != V.Name() || T.Kind() != V.Kind() {
return false
}
return haveIdenticalUnderlyingType(T.common(), V.common(), false)
}
go 1.17 reflect/type.go:1635 fixed the bug.
func haveIdenticalType(T, V Type, cmpTags bool) bool {
if cmpTags {
return T == V
}
if T.Name() != V.Name() || T.Kind() != V.Kind() || T.PkgPath() != V.PkgPath() {
return false
}
return haveIdenticalUnderlyingType(T.common(), V.common(), false)
}
Reproducible Example
import ( "fmt" "github.com/jinzhu/copier" "test/a" "test/b" )
func main() { aNode := a.TreeNode{ ID: "a1", Children: []a.TreeNode{ { ID: "a11", }, }, } bNode := b.TreeNode{} _ = copier.Copy(&bNode, &aNode) fmt.Println(aNode, bNode)
} -- go.mod -- module test -- a/node.go -- package a
type TreeNode struct { ID string Children []TreeNode } -- b/node.go -- package b
type TreeNode struct { ID string Children []TreeNode }