Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support optional array, string access and deep nil coalescing #583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ckganesan
Copy link
Contributor

@ckganesan ckganesan commented Feb 27, 2024

This PR is raised to add support for optional string and array access. #540 #547 #573

"g",
},
{
`'string'?.[7]`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exactly correct behavior I'm looking for.

In case array?.[7] operator ?. checks what array itself defined and not nil.

So the code

array?.[7]

will panic in there is no 7 element index.

What we can do is to alter [7] behavior with operator ?. after it.

array[7]?.field

In this case we can alter OpFetch and do not panic if 7 index does not exist.

This mean we, unfortunately, does not have a syntax to alter [7] behavior if it is the last postfix op.

But we can alter the whole "chain" in presence of ?? operator!

array[7].field ?? 'default'

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.

2 participants