Skip to content

Commit ab6b270

Browse files
author
Zaq? Wiedmann
committed
fix: gate transformers on valid non-nil destinations
This builds on #203 which attempted to provide a more flexible gating to running transformers. However upon testing #203 in my own environment, I ran into the first panic listed below. There are a variety of errors that can happen when trying to run reflection on zero values: 2 just from my testing of this PR ``` panic: reflect: call of reflect.Value.Type on zero Value panic: reflect: call of reflect.Value.FieldByName on zero Value ``` The panic specifically calls out zero values, but it's actual a more specific set of values which is covered by `reflect.IsValid`. I attempted to replace the check with `reflect.IsZero`, which ends up being too restrictive and breaks existing tests. I also attempted to solely use `reflect.IsZero` which is not restrictive enough and cause the later panic above in the tests. Thus I arrived on the combination in this PR which seems to strike the "right" balance.
1 parent fd3dfc9 commit ab6b270

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
7979
visited[h] = &visit{addr, typ, seen}
8080
}
8181

82-
if config.Transformers != nil && !isEmptyValue(dst) {
82+
if config.Transformers != nil && !isReflectNil(dst) && dst.IsValid() {
8383
if fn := config.Transformers.Transformer(dst.Type()); fn != nil {
8484
err = fn(dst, src)
8585
return

0 commit comments

Comments
 (0)