Skip to content

Commit 172aec3

Browse files
authored
dyn/convert: Properly detect zero float64 values (#3371)
https://github.com/databricks/cli/pull/3230/files#r2256951451
1 parent 1b812ab commit 172aec3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

libs/dyn/convert/from_typed_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,30 @@ func TestFromTypedStructZeroFieldsIntoExistingFields(t *testing.T) {
152152
}), nv)
153153
}
154154

155+
func TestFromTypedStructZeroFieldsIntoExistingFieldsFloat64(t *testing.T) {
156+
type Tmp struct {
157+
Foo float64 `json:"foo"`
158+
Bar float64 `json:"bar,omitempty"`
159+
BazBugz float64 `json:"baz_bugs,omitempty"`
160+
ForceSendFields []string `json:"-"`
161+
}
162+
163+
src := Tmp{ForceSendFields: []string{"BazBugz"}}
164+
165+
ref := dyn.V(map[string]dyn.Value{
166+
"foo": dyn.V(1.2),
167+
"bar": dyn.V(1.2),
168+
"baz_bugs": dyn.V(1.2),
169+
})
170+
171+
nv, err := FromTyped(src, ref)
172+
require.NoError(t, err)
173+
dynassert.Equal(t, dyn.V(map[string]dyn.Value{
174+
"foo": dyn.V(0.0),
175+
"baz_bugs": dyn.V(0.0),
176+
}), nv)
177+
}
178+
155179
func TestFromTypedStructSetFieldsRetainLocation(t *testing.T) {
156180
type Tmp struct {
157181
Foo string `json:"foo"`

libs/dyn/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (v Value) IsZero() bool {
154154
case KindInt:
155155
return v.v == 0
156156
case KindFloat:
157-
return v.v == 0
157+
return v.v == 0.0
158158
case KindTime:
159159
t := v.v.(Time)
160160
return t.IsZero()

0 commit comments

Comments
 (0)