This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 252023 - False-positive warning "Expected a conditional expression and instead saw an assignment."
Summary: False-positive warning "Expected a conditional expression and instead saw an ...
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.1
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-23 14:02 UTC by NukemBy
Modified: 2015-05-06 02:55 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description NukemBy 2015-04-23 14:02:28 UTC
I believe there is number of conditions when that hint is false-positive.

Please check the code below (I tried NetBeans IDE Dev (Build 201504230001)) and these links:

* http://stackoverflow.com/questions/5454012/jslint-warning-about-style-or-errror-about-conditional-expression

  If you want to make JSLint happy, you can add an explicit comparison to null:
    while((elem = document.getElementById("optionsDiv"+g)) !== null)

* https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/if...else

  If you need to use an assignment in a conditional expression, 
  a common practice is to put additional parentheses around the assignment. 

  For example:

    if( (x = y) ) {
       /* do the right thing */
    }

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

var value1 = 1, value2 = 2;

if( value1 = value2 ) {
    // definitelly valid warning
}
else if( value1 = getValue("condition A") ) {
    // typically valid warning ... 
}
else if( !(value1 = getValue("condition A")) ) {
    // OK: already does not complain, not sure why ...
}
else if( (value1 = getValue("condition A")) ) {
    // ... but (tentativelly) there should be 'some syntax' 
    // to let the inspector know that I indeed want to use implicit JS's
    // "value-to-boolean" convertion - probably additional brackets around 
    // expression is enough. 
    // 
    // Longer syntax that already works is below
    if( !!(value1 = getValue("condition A")) ) {
        // OK: already does not complain
    }
}
else if( (value1 = getValue("condition A")) !== null ) {
    // false positive warning - there is explicit boolean expression
}
else if( (value1 = getValue("condition B")) !== null ) {
    // false positive warning - there is explicit boolean expression
}
else if( (value1 = getValue("condition B")) !== null ) {
    // false positive warning - there is explicit boolean expression
}

//////////////////////////////////////////////////////////////////////

function getValue(condition) {
    if( condition )
        return "";
    return null;
}
Comment 1 Petr Pisl 2015-05-05 14:34:48 UTC
Thanks for reporting. Fixed in web-main.
Comment 2 Quality Engineering 2015-05-06 02:55:50 UTC
Integrated into 'main-silver', will be available in build *201505060001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/8775f8fcea32
User: Petr Pisl <ppisl@netbeans.org>
Log: #252023 - False-positive warning "Expected a conditional expression and instead saw an assignment."