Skip to content

Unreachable NaN branch in the constructor #132

Description

@jessealama

The Amount constructor parses String arguments with |StringNumericLiteral| and throws a RangeError if parsing fails. The algorithm then contains a branch that checks whether the parsed mathematical value is ~not-a-number~ and, if so, stores the Number value NaN. The intention is clear enough, but that branch is actually unreachable: |StringNumericLiteral| does not match "NaN". Thus, new Amount("NaN") throws a RangeError before checking for ~not-a-number~.

Comparing with how Number arguments are handled in the constructor, notice the asymmetry:

new Amount(NaN);      // Amount with value NaN
new Amount("NaN");    // RangeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions