Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion of zero valued scalar pointers to a dynamic value #1433

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/dyn/convert/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ func TestAdditional(t *testing.T) {
SliceOfPointer: []*string{nil},
})
})

t.Run("pointer to a empty string", func(t *testing.T) {
s := ""
assertFromTypedToTypedEqual(t, &s)
})
}
8 changes: 8 additions & 0 deletions libs/dyn/convert/from_typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func fromTyped(src any, ref dyn.Value, options ...fromTypedOptions) (dyn.Value,
return dyn.NilValue, nil
}
srcv = srcv.Elem()

// If a pointer to a scalar type points to a zero value, we should include
// that zero value in the dynamic representation.
// This is because by default a pointer is nil in Go, and it not being nil
// indicates its value was intentionally set to zero.
if !slices.Contains(options, includeZeroValues) {
options = append(options, includeZeroValues)
}
shreyas-goenka marked this conversation as resolved.
Show resolved Hide resolved
}

switch srcv.Kind() {
Expand Down
Loading