Repository navigation
fix: generate slice_len elements of any type and convert tagged values to named types - #112
Merged
bxcodec merged 1 commit intoNov 29, 2026
Conversation
…s to named types A slice_len tag with no other tag sent each element through getValueWithNoTag, which only handled integers and strings, so []float64, []bool, nested slices and float arrays failed with "Type is not supported by tag". Generate those elements with getFakedValue, as an untagged slice does. Tagged slice and map elements of a named type (type Name string) panicked in reflect.Set because the generated value has the underlying type. Convert it to the element or key type before setting it.
mansur-akhmadi
requested review from
bxcodec,
geshtng and
rubemlrm
as code owners
November 25, 2026 23:13
geshtng
approved these changes
Nov 29, 2026
bxcodec
approved these changes
Nov 29, 2026
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.
Fixes #111.
slice_lenset, slice and array elements are now generated bygetFakedValue, the same path an untagged slice uses.[]float64,[]float32,[]bool,[][]intand[3]float64withslice_lennow get values instead of an error.getValueWithNoTaghad no other caller and is removed.type Name stringno longer panics inreflect.Set/SetMapIndex.Integer and string elements under
slice_lencome out as before:getFakedValueuses the sameRandomIntegerBoundaryandrandomString(RandomStringLength, ...)thatgetValueWithNoTagused.Not changed:
slice_lencombined withboundary_start/boundary_endstill fails with "not written properly", because the leftover comma after removingslice_lenreaches the boundary parser. #108 strips that comma for provider tags; I left boundaries alone to keep this PR small.How it was tested
TestSliceLenElementTypes(float, float32, bool, named float, named string, nested slice, float array,len+slice_lenon a named string; 50 iterations, checks lengths, non-constant floats, both bool values) andTestOneOfNamedElementTypes(named slice and map withoneof, 50 iterations). Onmainthe first fails withType is not supported by tag.and the second panics withreflect.Set: value of type string is not assignable to type faker.sliceLenName.TestSliceLenUnsupportedElementType:[]anywithslice_lenstill returns an error rather than panicking (passes before and after).go test -race -run 'TestSliceLen|TestOneOfNamed' -count=50 .: okgofmt -l .: empty;go vet ./...: ok;go test -race -count=1 ./...: ok;golangci-lint run -c .golangci.yaml ./...(v2.13.2): 0 issues.make test(gotestsum/tparse) not run; the plaingo testcommands above were used instead.