Skip to content

fix(vm): clear error when fetching field from string at runtime#963

Merged
antonmedv merged 1 commit into
expr-lang:masterfrom
SAY-5:fix/fetch-string-property-access
May 26, 2026
Merged

fix(vm): clear error when fetching field from string at runtime#963
antonmedv merged 1 commit into
expr-lang:masterfrom
SAY-5:fix/fetch-string-property-access

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 26, 2026

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 for users expecting type 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.

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>
@antonmedv antonmedv merged commit 630bbf0 into expr-lang:master May 26, 2026
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.

Invalid/Inconsistent Error String on Invalid Field Access

2 participants