Repository navigation
feat: support arbitrary slices and arrays in ToSlice - #369
Open
AdamMagued wants to merge 1 commit into
Open
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
In ToSliceE, only []any and []map[string]any were explicitly handled in the type switch. When callers passed typed slices (such as []int, []string, or slices of custom structs) or fixed-size arrays, ToSliceE returned an error unable to cast to []any. Use reflection to inspect reflect.Slice and reflect.Array inputs, allocating a []any slice of corresponding length and converting each indexed element via Interface(). Add regression tests covering []int, []string, arrays, and struct slices. Fixes spf13#355
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #355
Currently, ToSliceE only converts slices that match []any or []map[string]any in its type switch. When provided typed slices (such as []int, []string, or slices of structs) or fixed-size arrays, ToSliceE fails with an error unable to cast to []any.
Technical Root Cause
ToSliceE lacked reflection fallback to decompose arbitrary slice and array types into generic []any elements.
Changes
Verification