fix(vm): clear error when fetching field from string at runtime#963
Merged
antonmedv merged 1 commit intoMay 26, 2026
Merged
Conversation
When a map value resolves to a string at runtime and is followed by a named-field access (e.g. v.k.missing where v.k is a string), the Fetch helper falls into the Array/Slice/String branch and calls ToInt on the field name. ToInt panics with "invalid operation: int(string)", which is confusing. Guard the branch: if the index is a string it can only be a property name, not an integer index, so panic with the canonical "cannot fetch <field> from <type>" message instead. Fixes expr-lang#962. Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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 a map value resolves to a string at runtime and is followed by a named-field access (e.g.
v.k.missingwherev.kis a string), theFetchhelper falls into theArray/Slice/Stringbranch and callsToInton the field name.ToIntpanics withinvalid operation: int(string), which is confusing for users expectingtype string has no field X.Guard the branch: if the index is a string it can only be a property name, not an integer index, so panic with the canonical
cannot fetch <field> from <type>message.Fixes #962.