fix(compose): copy map values before assigning nested fields - #1207
Open
serhiizghama wants to merge 2 commits into
Open
fix(compose): copy map values before assigning nested fields#1207serhiizghama wants to merge 2 commits into
serhiizghama wants to merge 2 commits into
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.
When two field mappings target sub-fields of the same map value (e.g.
a.Xanda.Yfor amap[string]struct{...}), the second one panics withreflect.Value.Set using unaddressable value.The first mapping creates the value through
newInstanceByType(addressable) and stores it. The second mapping reads it back withMapIndex, which is never addressable, and then tries toSeta field on it.assignOneonly handled the missing-key case, not the read-back case.Fixed by copying the read-back value into an addressable value before descending into it; the existing
SetMapIndexwrite-back at the end of the walk puts the updated struct back into the map, so the earlier field survives.Added a test that maps two sub-fields into one map value — it panics on the current code and passes with the fix.
go test ./compose/is green.