Skip to content

guard map key type before MapIndex in get#967

Open
netliomax25-code wants to merge 1 commit into
expr-lang:masterfrom
netliomax25-code:get-map-key-guard
Open

guard map key type before MapIndex in get#967
netliomax25-code wants to merge 1 commit into
expr-lang:masterfrom
netliomax25-code:get-map-key-guard

Conversation

@netliomax25-code
Copy link
Copy Markdown

The get builtin documents that it returns nil instead of panicking, but the map branch calls v.MapIndex(reflect.ValueOf(i)) directly. When the key is not assignable to the map's key type, or is an unhashable value reaching a map[any]any, reflect panics and the vm surfaces a raw reflect message like "reflect.Value.MapIndex: value of type ... is not assignable". Reachable from a dynamically typed map, e.g. get(m, [1,2]) where m has static type any. Check the key against the map key type and comparability first and fall back to nil, matching how missing keys already behave.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant