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

Bug: Dangling else in function calls #5163

Open
Inve1951 opened this issue Feb 20, 2019 · 2 comments
Open

Bug: Dangling else in function calls #5163

Inve1951 opened this issue Feb 20, 2019 · 2 comments
Labels

Comments

@Inve1951
Copy link
Contributor

I remember discussing dangling else in this repo but I can't seem to find the issue anymore. We did not discuss this specific case tho and I do think it's a bug.

Input Code

if coffee then if latte then 1 else 0

if coffee then brew if latte then 1 else 0

Expected Behavior

if (coffee) {
  if (latte) {
    1;
  } else {
    0;
  }
}

if (coffee) {
  brew(latte ? 1 : 0);
}

Current Behavior

if (coffee) {
  if (latte) {
    1;
  } else {
    0;
  }
}

if (coffee) {
  brew(latte ? 1 : void 0);
} else {
  0;
}

Possible Solution

Context

Environment

  • CoffeeScript version: 2.3.2
  • Node.js version: any
@vendethiel
Copy link
Collaborator

This is still #2342.

@carlsmith
Copy link
Contributor

carlsmith commented Mar 27, 2019

I don't know where it was discussed, but in the Changelog, the entry for 2.2.0 (February 1, 2018) includes this:

An inline if or switch statement with an ambiguous else, such as if no then if yes then alert 1 else alert 2, now compiles where the else always corresponds to the closest open then. Previously the behavior of an ambiguous else was unpredictable.

In short, the else should correspond to the most recently opened then, so yeah, I'm pretty sure you're right about this being a bug.

@GeoffreyBooth GeoffreyBooth changed the title [Bug] Dangling else in function calls Bug: Dangling else in function calls Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants