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

NaN is lexed as identifier, not as a number #393

Closed
hello2dj opened this issue May 12, 2020 · 2 comments · Fixed by #397
Closed

NaN is lexed as identifier, not as a number #393

hello2dj opened this issue May 12, 2020 · 2 comments · Fixed by #397
Labels
bug Something isn't working E-Easy Easy good first issue Good for newcomers
Milestone

Comments

@hello2dj
Copy link
Contributor

hello2dj commented May 12, 2020

Describe the bug
When lexing NaN, we don't get a number, we get an identifier.

To Reproduce
Run this JavaScript with cargo run -- -t {file}.js:

let a = NaN;

Expected behavior
The token for NaN should be :

Token {
    kind: NumericLiteral(
        Rational(NaN),
    ),
    pos: Position {
        column_number: 9,
        line_number: 1,
    },
},

Instead, we are getting:

Token {
    kind: Identifier(
        "NaN",
    ),
    pos: Position {
        column_number: 9,
        line_number: 1,
    },
},

This is controlled in https://github.com/jasonwilliams/boa/blob/master/boa/src/syntax/lexer/mod.rs#L591-L602. Appart from checking for true, false and null, we should also check for NaN and assign the correct rational, containing f64::NaN.

@hello2dj hello2dj added the bug Something isn't working label May 12, 2020
@Razican
Copy link
Member

Razican commented May 12, 2020

There are two issues related to this. First, #359 makes any call to typeof panic. But since that's being tracked there, this should track the fact that NaN is not lexed as a number, it's lexed as an identifier.

@Razican Razican changed the title boa exec typeof NaN will panic NaN is lexed as identifier, not as a number May 12, 2020
@Razican Razican added E-Easy Easy good first issue Good for newcomers labels May 12, 2020
@Razican
Copy link
Member

Razican commented May 12, 2020

I updated the description, so that it's easy to reproduce and fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working E-Easy Easy good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants