Skip to content

fix: support arbitrary slices and arrays in ToSliceE - #375

Open
mazkev wants to merge 1 commit into
spf13:masterfrom
mazkev:fix/to-slice-support-all-slices
Open

mazkev wants to merge 1 commit into
spf13:masterfrom
mazkev:fix/to-slice-support-all-slices

Conversation

@mazkev

@mazkev mazkev commented Nov 3, 2026

Copy link
Copy Markdown

Currently, ToSliceE(i any) only accepts []any and []map[string]any. Passing concrete slices (such as []string, []int, []bool) or arrays ([N]T) results in an error:
unable to cast []string of type []string to []interface {}

Meanwhile, typed slice functions like ToStringSliceE, ToIntSliceE, etc. support all generic slices and arrays via reflection.
This PR:

  1. Adds reflect.Slice and reflect.Array handling in ToSliceE so that any slice or array is safely converted to []any.
  2. Uses slices.Clone for []any, resolving the existing // TODO: use slices.Clone.
  3. Adds comprehensive unit test cases in TestSlice covering []string, []int, []bool, [2]string, and [2]int.

@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants