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?: Postfix conditional difference between try/iteration statements #5431

Closed
STRd6 opened this issue Oct 24, 2022 · 2 comments
Closed

Bug?: Postfix conditional difference between try/iteration statements #5431

STRd6 opened this issue Oct 24, 2022 · 2 comments

Comments

@STRd6
Copy link
Contributor

STRd6 commented Oct 24, 2022

Input Code

loop x() if y
try x() if y

Expected Behavior

if should be outside of both statements.

if (y) {
  while (true) {
    x();
  }
}

if (y) {
  try {
    x();
  } catch (error) {}
}

Current Behavior

if is inside try but outside of while.

if (y) {
  while (true) {
    x();
  }
}

try {
  if (y) {
    x();
  }
} catch (error) {}

Possible Solution

Maybe add documentation or adjust precedence to be consistent.

Context

Not sure if this is a bug but I just want to understand how postfix conditionals work with other statements accurately.

  • CoffeeScript version: 2.7.3

https://coffeescript.org/#try:loop%20x()%20if%20y%0Atry%20x()%20if%20y

@GeoffreyBooth
Copy link
Collaborator

I don’t think we can change this without it being a breaking change. This is one of those confusing things when everything is mushed onto one line; using indentation would eliminate the ambiguity and reliance on precedence. I’m not sure that documenting the precedence of inline try versus loop is worth it, since such ambiguous code shouldn’t be encouraged in the first place.

@STRd6
Copy link
Contributor Author

STRd6 commented Oct 25, 2022

That's fair

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants