Skip to content

NaN/undefined/Infinity should be matched as bindings rather than static values #317

Open

Description

@gibson042

(originally posted by @gibson042 in #293 (comment))

function pathological(x, undefined, NaN, Infinity) {
  return match (x) {
    when undefined: "undefined";
    when NaN: "NaN";
    when Infinity: "Infinity";
  }
}

Such bizarre bindings are honored elsewhere in the language (e.g., (NaN => [][NaN])("length") evaluates to 0 rather than undefined) and I believe discouraging the pattern via linters etc. is better than trumping explicit developer intent in match contexts where they are overridden.

Activity

  1. ljharb commented on Mar 18, 2024

    @ljharb
    Member

    Can you provide concrete examples of when this is actually intended by a developer? I can't say i've ever seen any (except that I've used undefined specifically to ensure it's the literal undefined)

  2. tabatkins commented on Mar 18, 2024

    @tabatkins
    Collaborator

    They are, now, matched like that per the README (they're just handled by the Variable Matcher section), but I'm not sure exactly what the spec PR currently says. I don't have a strong opinion either way.

  3. ljharb commented on Mar 18, 2024

    @ljharb
    Member

    I think that their ability to be bindings is a flaw in the language, and unless there's compelling evidence presented that developers ever actually want this behavior, this is an elegant opportunity to avoid furthering the mistake.

  4. gibson042 commented on Mar 18, 2024

    @gibson042
    MemberAuthor

    I strongly disagree that "avoid furthering the mistake [in just this one construct]" would be an improvement: #293 (comment)

    I'm just very sensitive to these kinds of epicycles—it's better IMO for the language to be consistently weird in having shadowable undefined/NaN/Infinity than for them to be shadowable in some contexts but not in others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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