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

Incorrect treatment of declarations named NaN/Infinity/undefined #1569

Closed
1 task done
gibson042 opened this issue Nov 23, 2024 · 2 comments
Closed
1 task done

Incorrect treatment of declarations named NaN/Infinity/undefined #1569

gibson042 opened this issue Nov 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@gibson042
Copy link

Bug Description

There are details at tc39/test262#4332 , but the summary is that Hermes incorrectly fails to reject top-level NaN/Infinity/undefined declarations and incorrectly fails to create (or at least respect) them in a deeper scope such as a block context.

  • I have run gradle clean and confirmed this bug does not occur with JSC

Hermes release version: 0.11.0

Steps To Reproduce

code example 1:

print('START');
const NaN = 1;
const Infinity = 1;
const undefined = 1;
print([NaN, Infinity, undefined].some(v => v === 1) ? 'FAIL WITH EFFECTS' : 'FAIL WITHOUT EFFECTS');

code example 2:

{
  const NaN = 1;
  const Infinity = 1;
  const undefined = 1;
  print([
    NaN === 1 ? 'PASS NaN' : 'FAIL NaN',
    Infinity === 1 ? 'PASS Infinity' : 'FAIL Infinity',
    undefined === 1 ? 'PASS undefined' : 'FAIL undefined',
  ].join(', '));
}

The Expected Behavior

Example 1 should throw a SyntaxError before anything happens (but instead prints "START" and "FAIL WITHOUT EFFECTS").

Example 2 should print "PASS NaN, PASS Infinity, PASS undefined" (but instead prints "FAIL NaN, FAIL Infinity, FAIL undefined").

@gibson042 gibson042 added the bug Something isn't working label Nov 23, 2024
@tmikov
Copy link
Contributor

tmikov commented Nov 24, 2024

Both examples pass with Hermes with --block-scoping. Without it, lexical declarations are simply aliases for var (for compatibility with weird internal use cases we have).

In Static Hermes, the second example passes as well, but the first fails. We will look into it (cc: @avp).

@avp
Copy link
Contributor

avp commented Nov 26, 2024

Fixed in Static Hermes in 2897b34

@avp avp closed this as completed Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants