Skip to content

fix: type find/first/get as any when they can return nil - #992

Open
TastyHeadphones wants to merge 1 commit into
expr-lang:masterfrom
TastyHeadphones:fix/nilable-builtins-type
Open

TastyHeadphones wants to merge 1 commit into
expr-lang:masterfrom
TastyHeadphones:fix/nilable-builtins-type

Conversation

@TastyHeadphones

Copy link
Copy Markdown

find, findIndex, first and get can return nil, but the type checker treated them as the element type (or int). With AsInt + WarnOnAny that compiles and then blows up at Run with int(). find over []any already failed the check because the element type is any.

Type those builtins as any so WarnOnAny catches them the same way. Field access and arithmetic on the result still type-check.

Fixes #989

find/findLast/findIndex/findLastIndex/first/last/get can return nil.
Typing them as the element (or int) let AsInt+WarnOnAny accept
expressions that then fail at Run with int(<nil>). Type them as any
so WarnOnAny catches the mismatch, matching find over []any.

Fixes expr-lang#989

This branch has not been deployed

No deployments
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.

find, findIndex, first and get are type-checked as the element type where they return nil

1 participant