forked from qt-creator/qt-creator
Revert: qmljs: add check for comparisons not depending on values
The warnings produced by these checks have always been somewhat broken. Ever since they were added people users complained about the M325 warnings because they were confusing or because of false positives. Fixes: QTCREATORBUG-29601 Change-Id: Ifac1ed0819a05251b3c4b583627cc45553e3d680 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -1364,14 +1364,6 @@ static bool shouldAvoidNonStrictEqualityCheck(const Value *lhs, const Value *rhs
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool equalIsAlwaysFalse(const Value *lhs, const Value *rhs)
|
|
||||||
{
|
|
||||||
if ((lhs->asNullValue() || lhs->asUndefinedValue())
|
|
||||||
&& (rhs->asNumberValue() || rhs->asBooleanValue() || rhs->asStringValue()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isIntegerValue(const Value *value)
|
static bool isIntegerValue(const Value *value)
|
||||||
{
|
{
|
||||||
if (value->asNumberValue() || value->asIntValue())
|
if (value->asNumberValue() || value->asIntValue())
|
||||||
@@ -1402,33 +1394,6 @@ static bool isBooleanValue(const Value *value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool strictCompareConstant(const Value *lhs, const Value *rhs)
|
|
||||||
{
|
|
||||||
// attached properties and working at runtime cases may be undefined at evaluation time
|
|
||||||
if (lhs->asUndefinedValue() || rhs->asUndefinedValue())
|
|
||||||
return false;
|
|
||||||
if (lhs->asUnknownValue() || rhs->asUnknownValue())
|
|
||||||
return false;
|
|
||||||
if (lhs->asFunctionValue() || rhs->asFunctionValue()) // function evaluation not implemented
|
|
||||||
return false;
|
|
||||||
if (isIntegerValue(lhs) && isIntegerValue(rhs))
|
|
||||||
return false;
|
|
||||||
if (isStringValue(lhs) && isStringValue(rhs))
|
|
||||||
return false;
|
|
||||||
if (isBooleanValue(lhs) && isBooleanValue(rhs))
|
|
||||||
return false;
|
|
||||||
if (lhs->asBooleanValue() && !rhs->asBooleanValue())
|
|
||||||
return true;
|
|
||||||
if (lhs->asNumberValue() && !rhs->asNumberValue())
|
|
||||||
return true;
|
|
||||||
if (lhs->asStringValue() && !rhs->asStringValue())
|
|
||||||
return true;
|
|
||||||
if (lhs->asObjectValue() && (!rhs->asObjectValue() || !rhs->asNullValue()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Check::visit(BinaryExpression *ast)
|
bool Check::visit(BinaryExpression *ast)
|
||||||
{
|
{
|
||||||
const QString source = _doc->source();
|
const QString source = _doc->source();
|
||||||
@@ -1454,18 +1419,6 @@ bool Check::visit(BinaryExpression *ast)
|
|||||||
|| shouldAvoidNonStrictEqualityCheck(rhsValue, lhsValue)) {
|
|| shouldAvoidNonStrictEqualityCheck(rhsValue, lhsValue)) {
|
||||||
addMessage(MaybeWarnEqualityTypeCoercion, ast->operatorToken);
|
addMessage(MaybeWarnEqualityTypeCoercion, ast->operatorToken);
|
||||||
}
|
}
|
||||||
if (equalIsAlwaysFalse(lhsValue, rhsValue)
|
|
||||||
|| equalIsAlwaysFalse(rhsValue, lhsValue))
|
|
||||||
addMessage(WarnLogicalValueDoesNotDependOnValues, ast->operatorToken);
|
|
||||||
}
|
|
||||||
if (ast->op == QSOperator::StrictEqual || ast->op == QSOperator::StrictNotEqual) {
|
|
||||||
Evaluate eval(&_scopeChain);
|
|
||||||
const Value *lhsValue = eval(ast->left);
|
|
||||||
const Value *rhsValue = eval(ast->right);
|
|
||||||
if (strictCompareConstant(lhsValue, rhsValue)
|
|
||||||
|| strictCompareConstant(rhsValue, lhsValue)) {
|
|
||||||
addMessage(WarnLogicalValueDoesNotDependOnValues, ast->operatorToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check odd + ++ combinations
|
// check odd + ++ combinations
|
||||||
|
|||||||
@@ -229,8 +229,6 @@ StaticAnalysisMessages::StaticAnalysisMessages()
|
|||||||
Tr::tr("Hit maximum recursion limit when visiting AST."));
|
Tr::tr("Hit maximum recursion limit when visiting AST."));
|
||||||
newMsg(ErrTypeIsInstantiatedRecursively, Error,
|
newMsg(ErrTypeIsInstantiatedRecursively, Error,
|
||||||
Tr::tr("Type cannot be instantiated recursively (%1)."), 1);
|
Tr::tr("Type cannot be instantiated recursively (%1)."), 1);
|
||||||
newMsg(WarnLogicalValueDoesNotDependOnValues, Warning,
|
|
||||||
Tr::tr("Logical value does not depend on actual values."));
|
|
||||||
newMsg(ErrToManyComponentChildren, Error,
|
newMsg(ErrToManyComponentChildren, Error,
|
||||||
Tr::tr("Components are only allowed to have a single child element."));
|
Tr::tr("Components are only allowed to have a single child element."));
|
||||||
newMsg(WarnComponentRequiresChildren, Warning,
|
newMsg(WarnComponentRequiresChildren, Warning,
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ enum Type {
|
|||||||
ErrShorterStringValueExpected = 322,
|
ErrShorterStringValueExpected = 322,
|
||||||
ErrInvalidArrayValueLength = 323,
|
ErrInvalidArrayValueLength = 323,
|
||||||
ErrHitMaximumRecursion = 324,
|
ErrHitMaximumRecursion = 324,
|
||||||
WarnLogicalValueDoesNotDependOnValues = 325,
|
|
||||||
ErrToManyComponentChildren = 326,
|
ErrToManyComponentChildren = 326,
|
||||||
WarnComponentRequiresChildren = 327,
|
WarnComponentRequiresChildren = 327,
|
||||||
WarnDuplicateImport = 400,
|
WarnDuplicateImport = 400,
|
||||||
|
|||||||
@@ -12,42 +12,30 @@ Rectangle {
|
|||||||
|
|
||||||
if (s == s) {}
|
if (s == s) {}
|
||||||
if (s == n) {} // 126 15 16
|
if (s == n) {} // 126 15 16
|
||||||
if (s == N) {} // 325 15 16
|
|
||||||
if (s == u) {} // 325 15 16
|
|
||||||
if (s == b) {} // 126 15 16
|
if (s == b) {} // 126 15 16
|
||||||
if (s == o) {} // 126 15 16
|
if (s == o) {} // 126 15 16
|
||||||
if (s == k) {} // 126 15 16
|
if (s == k) {} // 126 15 16
|
||||||
|
|
||||||
if (n == s) {} // 126 15 16
|
if (n == s) {} // 126 15 16
|
||||||
if (n == n) {}
|
if (n == n) {}
|
||||||
if (n == N) {} // 325 15 16
|
|
||||||
if (n == u) {} // 325 15 16
|
|
||||||
if (n == b) {} // 126 15 16
|
if (n == b) {} // 126 15 16
|
||||||
if (n == o) {} // 126 15 16
|
if (n == o) {} // 126 15 16
|
||||||
if (n == k) {} // 126 15 16
|
if (n == k) {} // 126 15 16
|
||||||
|
|
||||||
if (N == s) {} // 325 15 16
|
|
||||||
if (N == n) {} // 325 15 16
|
|
||||||
if (N == N) {}
|
if (N == N) {}
|
||||||
if (N == u) {}
|
if (N == u) {}
|
||||||
|
|
||||||
if (N == b) {} // 325 15 16
|
|
||||||
if (N == o) {}
|
if (N == o) {}
|
||||||
if (N == k) {} // 126 15 16
|
if (N == k) {} // 126 15 16
|
||||||
|
|
||||||
if (u == s) {} // 325 15 16
|
|
||||||
if (u == n) {} // 325 15 16
|
|
||||||
if (u == N) {}
|
if (u == N) {}
|
||||||
if (u == u) {}
|
if (u == u) {}
|
||||||
if (u == b) {} // 325 15 16
|
|
||||||
if (u == o) {}
|
if (u == o) {}
|
||||||
if (u == k) {} // 126 15 16
|
if (u == k) {} // 126 15 16
|
||||||
|
|
||||||
if (b == s) {} // 126 15 16
|
if (b == s) {} // 126 15 16
|
||||||
if (b == n) {} // 126 15 16
|
if (b == n) {} // 126 15 16
|
||||||
|
|
||||||
if (b == N) {} // 325 15 16
|
|
||||||
if (b == u) {} // 325 15 16
|
|
||||||
if (b == b) {}
|
if (b == b) {}
|
||||||
if (b == o) {} // 126 15 16
|
if (b == o) {} // 126 15 16
|
||||||
if (b == k) {} // 126 15 16
|
if (b == k) {} // 126 15 16
|
||||||
@@ -69,35 +57,19 @@ Rectangle {
|
|||||||
if (k == k) {} // 126 15 16
|
if (k == k) {} // 126 15 16
|
||||||
|
|
||||||
if (s === s) {}
|
if (s === s) {}
|
||||||
if (s === n) {} // 325 15 17
|
|
||||||
if (s === N) {} // 325 15 17
|
|
||||||
if (s === u) {}
|
if (s === u) {}
|
||||||
if (s === b) {} // 325 15 17
|
|
||||||
if (s === o) {} // 325 15 17
|
|
||||||
if (s === k) {}
|
if (s === k) {}
|
||||||
if (s !== s) {}
|
if (s !== s) {}
|
||||||
if (s !== n) {} // 325 15 17
|
|
||||||
if (s !== N) {} // 325 15 17
|
|
||||||
if (s !== u) {}
|
if (s !== u) {}
|
||||||
if (s !== b) {} // 325 15 17
|
|
||||||
if (s !== o) {} // 325 15 17
|
|
||||||
if (s !== k) {}
|
if (s !== k) {}
|
||||||
|
|
||||||
if (n === s) {} // 325 15 17
|
|
||||||
if (n === n) {}
|
if (n === n) {}
|
||||||
if (n === N) {} // 325 15 17
|
|
||||||
if (n === u) {}
|
if (n === u) {}
|
||||||
if (n === b) {} // 325 15 17
|
|
||||||
if (n === o) {} // 325 15 17
|
|
||||||
if (n === k) {}
|
if (n === k) {}
|
||||||
|
|
||||||
if (N === s) {} // 325 15 17
|
|
||||||
if (N === n) {} // 325 15 17
|
|
||||||
if (N === N) {}
|
if (N === N) {}
|
||||||
if (N === u) {}
|
if (N === u) {}
|
||||||
|
|
||||||
if (N === b) {} // 325 15 17
|
|
||||||
if (N === o) {} // 325 15 17
|
|
||||||
if (N === k) {}
|
if (N === k) {}
|
||||||
|
|
||||||
if (u === s) {}
|
if (u === s) {}
|
||||||
@@ -108,21 +80,11 @@ Rectangle {
|
|||||||
if (u === o) {}
|
if (u === o) {}
|
||||||
if (u === k) {}
|
if (u === k) {}
|
||||||
|
|
||||||
if (b === s) {} // 325 15 17
|
|
||||||
if (b === n) {} // 325 15 17
|
|
||||||
|
|
||||||
if (b === N) {} // 325 15 17
|
|
||||||
if (b === u) {}
|
if (b === u) {}
|
||||||
if (b === b) {}
|
if (b === b) {}
|
||||||
if (b === o) {} // 325 15 17
|
|
||||||
if (b === k) {}
|
if (b === k) {}
|
||||||
|
|
||||||
if (o === s) {} // 325 15 17
|
|
||||||
if (o === n) {} // 325 15 17
|
|
||||||
if (o === N) {} // 325 15 17
|
|
||||||
if (o === u) {}
|
if (o === u) {}
|
||||||
if (o === b) {} // 325 15 17
|
|
||||||
if (o === o) {} // 325 15 17
|
|
||||||
if (o === k) {}
|
if (o === k) {}
|
||||||
|
|
||||||
if (k === s) {}
|
if (k === s) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user