Skip to content

fix(parser): support optional chaining on slice expressions#945

Open
eyupcanakman wants to merge 1 commit intoexpr-lang:masterfrom
eyupcanakman:fix/optional-chain-slice-822
Open

fix(parser): support optional chaining on slice expressions#945
eyupcanakman wants to merge 1 commit intoexpr-lang:masterfrom
eyupcanakman:fix/optional-chain-slice-822

Conversation

@eyupcanakman
Copy link
Copy Markdown

foo?.[0:1] panics at runtime when foo is nil. Optional chaining works for member access (foo?.bar) through MemberNode.Optional + OpJumpIfNil, but SliceNode had no equivalent.

Added the same Optional + OpJumpIfNil pattern to SliceNode.

Fixes #822

Allow nil?.[from:to] to return nil instead of erroring with "cannot
slice unknown". Add Optional field to SliceNode, propagate it through
parser, checker, and compiler using the same pattern as MemberNode
optional chaining.

Fixes expr-lang#822
@eyupcanakman eyupcanakman force-pushed the fix/optional-chain-slice-822 branch from cf006b6 to d239381 Compare May 7, 2026 14:01
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.

Unexpected behaviour - cannot slice unkown with ?.

1 participant