Skip to content

Cell paths: make optional path members short-circuit#8554

Merged
sophiajt merged 1 commit intonushell:mainfrom
rgwood:optional-short-circuit
Mar 22, 2023
Merged

Cell paths: make optional path members short-circuit#8554
sophiajt merged 1 commit intonushell:mainfrom
rgwood:optional-short-circuit

Conversation

@rgwood
Copy link
Copy Markdown
Contributor

@rgwood rgwood commented Mar 21, 2023

This is a follow-up to #8379 and #8502.

This PR makes it so that the new ? syntax for marking a path member as optional short-circuits, as voted on in the 8502 poll. Previously, { foo: 123 }.bar?.baz would raise an error:

> { foo: 123 }.bar?.baz
  × Data cannot be accessed with a cell path
   ╭─[entry #15:1:1]
 1 │ { foo: 123 }.bar?.baz
   ·                   ─┬─
   ·                    ╰── nothing doesn't support cell paths
   ╰────

Here's what was happening:

  1. The bar? path member access returns nothing because there is no field named bar on the record
  2. The baz path member access fails when trying to access a baz field on that nothing value

After this change, { foo: 123 }.bar?.baz returns nothing; the failed bar? access immediately returns nothing and the baz access never runs.

@amtoine
Copy link
Copy Markdown
Member

amtoine commented Mar 21, 2023

that's very nice 😮

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.

3 participants