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

Confusing error message for deterministic equality check #2858

Open
shicks opened this issue Mar 20, 2018 · 0 comments
Open

Confusing error message for deterministic equality check #2858

shicks opened this issue Mar 20, 2018 · 0 comments

Comments

@shicks
Copy link
Member

shicks commented Mar 20, 2018

repro

The following error message is a bit confusing:

/** @constructor */
function Foo() {}
/** @constructor */
function Bar() {}

function f(/** ?Foo */ foo, /** ?Bar */ bar) {
  if (foo === bar) throw '';
}
input0:7: WARNING - condition always evaluates to false
left : (Foo|null)
right: (Bar|null)
  if (foo === bar) throw '';
      ^^^^^^^^^^^

This is inaccurate - the condition does not always evaluate to false. It is suspicious code and probably not what the user intended, but to be completely accurate we should check if the two sides both include null/undefined and if that's the case then add a bit about "for non-trivial values", or say "instead check foo == null && bar == null" or something.

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

1 participant