When a field in a struct requires a non-pointer value, and --pointer-receiver is specified, incorrect functions are generated.
For example:
package sample
type Foo struct {
B Bar
}
type Bar struct {
S string
}
Run the command:
$ deep-copy -type Foo -type Bar --pointer-receiver -o sample/sample_deepcopy.go ./sample
It generates:
// generated by deep-copy -type Foo -type Bar --pointer-receiver -o sample/sample_deepcopy.go ./sample; DO NOT EDIT.
package sample
// DeepCopy generates a deep copy of *Foo
func (o *Foo) DeepCopy() *Foo {
var cp Foo = *o
cp.B = o.B.DeepCopy()
return &cp
}
// DeepCopy generates a deep copy of *Bar
func (o *Bar) DeepCopy() *Bar {
var cp Bar = *o
return &cp
}
o.B.DeepCopy() returns *Bar, but Foo.B want Bar(non-pointer), so it would fail at compile time.
sample/sample_deepcopy.go:8:7: cannot use o.B.DeepCopy() (type *Bar) as type Bar in assignment
The same problem is also found when a field requires pointer value and --pointer-receiver is not used.
When a field in a struct requires a non-pointer value, and
--pointer-receiver
is specified, incorrect functions are generated.For example:
Run the command:
It generates:
o.B.DeepCopy()
returns*Bar
, butFoo.B
wantBar
(non-pointer), so it would fail at compile time.The same problem is also found when a field requires pointer value and
--pointer-receiver
is not used.