Skip to content

Expressions starting from _ are treated as placeholders in match cases #1025

Closed
rugk/ethercalc
#4

Description

@pepkin88

Example:

match a
| _.isString => 1
| (_.isString) => 1

Result:

var ref$;
switch (ref$ = [a], false) {
case !true:
  1;
  break;
case !_.isString(ref$[0]):
  1;
}

Expected result:

var ref$;
switch (ref$ = [a], false) {
case !_.isString(ref$[0]):
  1;
  break;
case !_.isString(ref$[0]):
  1;
}

The example shows, that wrapping the expression in parentheses is enough to bypass this bug.

Activity

  1. rhendric commented on Mar 26, 2018

    @rhendric
    Collaborator

    Oh, match. The undocumented, largely untested, experimental feature that somehow people keep discovering anyway.

    This sure does look like a bug, but I don't know whether this should be an error, your expected result, or something else. _ has special meaning inside match, which is complicated by the fact that _ is also used to create a partial-application function and as far as I know, every case of a match expression should be interpreted as a function (unless it isn't, like with constants).

    I don't really intend to do anything to improve the state of match, unless someone feels like fully and properly specifying its behavior. The good news is, as an experimental undocumented feature, I also wouldn't feel even a tiny bit bad about ripping it out and replacing it with something else. You were all warned. 🙂

  2. pepkin88 commented on Mar 26, 2018

    @pepkin88
    ContributorAuthor

    OK, fair enough.

    I drew an analogy to the partial application or switch's default, where only a standalone underscore has a special meaning. In those cases using _.toString wouldn't trigger anything special.

    I might fix it later. For now, let this issue be a walk-around suggestion.

  3. pepkin88 commented on Apr 2, 2018

    @pepkin88
    ContributorAuthor

    Related issue with a plausible use case scenario:

    This:

    (_.isPlainObject || _.isArray) value

    compiles to:

    true || true;

    instead of:

    _.isPlainObject(value) || _.isArray(value);

    Although I think this feature is a real gotcha and makes sense only in the context of match, it actually is documented.

  4. rhendric commented on Apr 2, 2018

    @rhendric
    Collaborator

    Ha, okay, you got me! This should be fixed.

  5. pepkin88 commented on Apr 2, 2018

    @pepkin88
    ContributorAuthor

    This looks like an easy one I could tackle, but only from next week.

  6. rhendric commented on Apr 2, 2018

    @rhendric
    Collaborator

    I'll hold it for you then.

  7. anant-svc commented on Jun 11, 2018

    @anant-svc

    Hi, tried to get expected result @pepkin88 needed using below:

    u = _
    match a
    | u.isString => 1
    | (u.isString) => 1
    

    Result:

    var u, ref$;
    u = _;
    switch (ref$ = [a], false) {
    case !u.isString(ref$[0]):
      1;
      break;
    case !u.isString(ref$[0]):
      1;
    }
    
  8. added 4 commits that reference this issue on Jul 29, 2018
    b24db83
    ba88e2f
    5c71eaa
    2881144
  9. added a commit that references this issue on Jul 30, 2018
    7b91a13
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions