Skip to content

Commit e048a51

Browse files
committed
remove generic method signature in favor of 'any'
Depends on reflect under the hood anyway
1 parent aef7f32 commit e048a51

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

testutil/faker.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ func Fake[T any](t *testing.T, faker *gofakeit.Faker, seed T) T {
2828

2929
// mergeZero merges the fields of src into dst, but only if the field in dst is
3030
// currently the zero value.
31-
func mergeZero[T any](dst *T, src T) {
31+
// Make sure `dst` is a pointer to a struct, otherwise the fields are not assignable.
32+
func mergeZero(dst any, src any) {
33+
srcv := reflect.ValueOf(src)
34+
if srcv.Kind() == reflect.Ptr {
35+
srcv = srcv.Elem()
36+
}
3237
remain := [][2]reflect.Value{
33-
{reflect.ValueOf(dst).Elem(), reflect.ValueOf(src)},
38+
{reflect.ValueOf(dst).Elem(), srcv},
3439
}
3540

3641
// Traverse the struct fields and set them only if they are currently zero.

0 commit comments

Comments
 (0)