Skip to content

fix(compose): copy map values before assigning nested fields - #1207

Open
serhiizghama wants to merge 2 commits into
cloudwego:mainfrom
serhiizghama:fix/map-value-nested-field-unaddressable
Open

fix(compose): copy map values before assigning nested fields#1207
serhiizghama wants to merge 2 commits into
cloudwego:mainfrom
serhiizghama:fix/map-value-nested-field-unaddressable

Conversation

@serhiizghama

Copy link
Copy Markdown

When two field mappings target sub-fields of the same map value (e.g. a.X and a.Y for a map[string]struct{...}), the second one panics with reflect.Value.Set using unaddressable value.

The first mapping creates the value through newInstanceByType (addressable) and stores it. The second mapping reads it back with MapIndex, which is never addressable, and then tries to Set a field on it. assignOne only 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 SetMapIndex write-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.

@CLAassistant

CLAassistant commented Aug 24, 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

Development

Successfully merging this pull request may close these issues.

2 participants