Closed Bug 382622 Opened 17 years ago Closed 6 years ago

Expand the "useless expression" strict warning to cover = mistyped as ==

Categories

(Core :: JavaScript Engine, enhancement)

x86
macOS
enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: jruderman, Unassigned)

References

Details

function() { var c; c == 0; }
fires  the "useless expression" warning, but
    function() { c == 0; }
does not.  I think the latter should as well, because even though the subexpression c is useful, the comparison is useless.

Bug 382584 contains an example of a bug where an assignment (=) was mistyped as comparison (==).  In that instance, the LHS was a local variable, so the warning was able to fire.  But if the LHS had been a global variable or a property of something, the existing warning would not have fired.
Blocks: 296661
Assignee: general → nobody
There's a difference between
function() { var c; c == 0; }
and
function() { c == 0; }

The second one sets/changes a global variable called 'c', hence it's not a "useless" expression.

Working as per Javascript specification. Therefore I suggest to close this bug.
Indeed, my mistake (I tohught it was c=0;}. c==0 is indeed a useless expression.
However, if 'c' variable is defined through a getter, then the getter could have side effects. Then that call would not be useless.
Any local variable access is nowadays considered an effectful expression (see bug 1167823), therefore resolving as WONTFIX.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.