fix: handle nested binary expressions in instrumentFile#25
Merged
Conversation
Rewrite instrumentFile to use bottom-up replacement building so that nested binary comparisons (e.g. (a > b) == flag) instrument all mutation targets instead of panicking on overlapping byte ranges. Inner replacement text is embedded into outer replacements, and only root-level replacements are applied to the source. Closes #23
Add testdata/project/nested.go with patterns that triggered #23: - comparison in equality: (a > b) == flag - double nil-check in equality: (x != nil) == (y != nil) - triple nesting: ((a > b) == flag) != expected - side-by-side comparisons: (a > b) == (c < d) - comparison in inequality: (a <= b) != expected - nil-check with comparison: p == nil, (*p > threshold) == true Update TestDiscoverAll expected count from 11 to 17.
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
slice bounds out of range) when instrumenting nested binary comparisons like(a > b) == flag,(x != nil) == (y != nil), or deeper nestinginstrumentFileto build replacement text bottom-up: inner mutations are embedded into outer replacement text, so all mutation targets are preserved instead of only the outermosttestdata/project/nested.go) covering 6 nested comparison patterns that previously triggered the panicCloses #23
Test plan
go test ./... -racepassesgo vet ./...passestestdata/projectandhashicorp/go-multierrorby comparing JSON output (old vs new, identical except duration)testdata/project/nested.go— all 16 nested mutations are killed by tests