Stringify non-string map keys in ToStringMapInt/Int64 reflect path - #359
Open
nikolauspschuetz wants to merge 1 commit into
Open
Stringify non-string map keys in ToStringMapInt/Int64 reflect path#359nikolauspschuetz wants to merge 1 commit into
nikolauspschuetz wants to merge 1 commit into
Conversation
The reflect fallback in toStringMapIntE wrote the original key into the result map via reflect.SetMapIndex, which panics for a map whose key is not a string (e.g. map[int]int), since the result map is map[string]T. Convert the key with ToString and assign directly, matching the typed map[any]... cases, and add a non-string-key test.
nikolauspschuetz
marked this pull request as ready for review
August 26, 2026 19:56
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.
ToStringMapIntE/ToStringMapInt64Epanic on a map whose key type isn'tstringorany(e.g.map[int]int): the reflect fallback intoStringMapIntEdoesmVal.SetMapIndex(keyVal, ...)into amap[string]T, and reflect rejects the non-string key (value of type int is not assignable to type string).This stringifies the key with
ToStringand assigns directly — matching the existingmap[any]...cases — and adds amap[int]intregression case toTestStringMapInt.Verified: the new case fails on current code and passes with the fix; the full
castsuite stays green.Developed with AI assistance (Claude Code); I directed, reviewed, and verified it locally.