Fix generated examples with small maximum lengths - #4009
Merged
Merged
Conversation
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.
Goa can panic while generating examples for a valid array with
MaxLength(1). With no minimum,NewLengthsubtracts a random value from zero through two; subtracting two produces a negative allocation size. A maximum of zero has the same problem.Bound the possible subtraction by the declared maximum before generating the value. Zero and one now produce only valid lengths. Maxima of two or more preserve the existing calculation, example-size cap, and number of random draws. The shared calculation fixes string, byte, array, and map examples without changing the DSL or validation contracts.
The new deterministic regression reproduces 12 failures on the old implementation and passes all 51 cases with the fix. The complete
./exprsuite passes on Go 1.27.1: 227 top-level tests and 486 subtests. Tests exercise both the length calculation and actual example construction, including unchanged larger bounds.No runtime wire format, caller API, or persisted data changes; no migration is needed. Consumers encountering this generation failure should update Goa and regenerate. Only generated example values for these small maximum lengths may change.