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

Problems with optional chaining and nullish coalesce operators #1688

Closed
andreabergia opened this issue Oct 10, 2024 · 1 comment
Closed

Problems with optional chaining and nullish coalesce operators #1688

andreabergia opened this issue Oct 10, 2024 · 1 comment
Labels
bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Milestone

Comments

@andreabergia
Copy link
Contributor

While working on #1684 me and my colleagues @0xe and @nabacg have discovered a few problems with the two newly implemented operators.

For the optional chaining ?. we do not support the syntax a?.[ expr ], which #1684 would fix.
Also, while the original PR #1593 implemented partial support for optional function calling, i.e. a.b?.() works, it does not support properly other kind of function calls such as a?.() or a[b]?.().

For nullish coalesce operator ?? we have instead discovered that we "leak" some temporary state. In #1624 a fix was implemented so that something like f() ?? 42 would evaluate f() just once by creating a temporary name. However, that temp name leaks out to the containing scope, i.e.:

a = 1;
a ?? 42;
this.$0  // evaluates to "1"
Object.keys(this)  // will contain $0

Furthermore, we can even overwrite variables:

$0 = false;
a = true;
a ?? 42;
$0 // true

Given the similarities between these operators and the problems and missing features, we are trying to come up with a single approach that works with all cases. We hope to submit a PR in the next few weeks to fix all of this.

@p-bakker p-bakker added bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec labels Oct 10, 2024
@p-bakker p-bakker added this to the Release 1.7.16 milestone Oct 10, 2024
@andreabergia
Copy link
Contributor Author

Should be fixed since the related PRs have been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Projects
None yet
Development

No branches or pull requests

2 participants