-
Notifications
You must be signed in to change notification settings - Fork 75
Closed
Description
If a struct has map, slice, or pointer fields which have an initial value of nil, Set() will set them to empty (zero) values, even if the field has no "default" tag. See this test case:
type TT struct{}
type SS struct {
Ptr *TT
Slice []string
Map map[string]interface{}
}
func TestEmptySlice(t *testing.T) {
s := SS{}
err := Set(&s)
if err != nil {
t.Fatalf("Set() returned error: %#v", err)
}
if s.Ptr != nil {
t.Error("Set() initialized nil pointer")
}
if s.Slice != nil {
t.Error("Set() initialized nil slice")
}
if s.Map != nil {
t.Error("Set() initialized nil map")
}
}
Seems like, if the field has no "default" tag, and there is nothing to recurse into (because the value is nil), it should be left unchanged.
I think this was a side effect of the last change for recursing into nested values with no "default" tag.
Metadata
Metadata
Assignees
Labels
No labels