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

Comparison operator negation rules can be incorrect #902

Closed
alangpierce opened this issue Mar 6, 2017 · 0 comments
Closed

Comparison operator negation rules can be incorrect #902

alangpierce opened this issue Mar 6, 2017 · 0 comments
Assignees

Comments

@alangpierce
Copy link
Member

@alangpierce alangpierce commented Mar 6, 2017

decaffeinate is producing the wrong JavaScript based on my CoffeeScript input:

unless NaN > 1
  console.log 'first'
else
  console.log 'second'

(repl)

I get this output:

if (NaN <= 1) {
  console.log('first');
} else {
  console.log('second');
}

Here's what I expect it to be instead:

if (!(NaN > 1)) {
  console.log('first');
} else {
  console.log('second');
}

This is causing at least two problems in atom. I think this negation behavior probably needs to be behind a --loose flag, since it doesn't work for operands like NaN and undefined.

@alangpierce alangpierce self-assigned this Mar 6, 2017
alangpierce added a commit to alangpierce/decaffeinate that referenced this issue Mar 6, 2017
Fixes decaffeinate#902

For both normal binary operators and chained comparison operators, we need to be
careful about rewriting `!(a < b)` as `a >= b`, since the rewrite isn't correct
for cases like `NaN`. Now, we just do the simpler negation by default and only
do the nicer-looking one with an opt-in flag.
alangpierce added a commit that referenced this issue Mar 6, 2017
Fixes #902

For both normal binary operators and chained comparison operators, we need to be
careful about rewriting `!(a < b)` as `a >= b`, since the rewrite isn't correct
for cases like `NaN`. Now, we just do the simpler negation by default and only
do the nicer-looking one with an opt-in flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.