go-copy icon indicating copy to clipboard operation
go-copy copied to clipboard

Cannot copy a struct that embedding an interface

Open tomtwinkle opened this issue 4 years ago • 0 comments

Hi, I have a problem.

If you use go-copy to copy a "struct embedding interface" like in the sample, an error will occur.

package main

import (
	"github.com/liguangsheng/go-copy"
	"log"
)

type Interface interface {}

type SampleA struct {
	Interface
	FieldStr string
	FieldInt int
}

type SampleB struct {
	FieldStr string
	FieldInt int
}

func main() {
	src := SampleA{
		FieldStr: "test",
		FieldInt: 100,
	}
	var dest SampleB

	copier := copy.NewCopier()
	if err := copier.Copy(&dest, &src); err != nil {
		log.Fatal(err)
	}
	log.Print(dest)
}

tomtwinkle avatar Feb 25 '21 08:02 tomtwinkle