diff options
author | Christian Stenger <christian.stenger@qt.io> | 2022-04-13 13:11:57 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2022-04-22 05:24:21 +0000 |
commit | 9656eb9e7a13213c51a9674a50f710b02abbe124 (patch) | |
tree | ce9f99ef898eae6dbea0e13fbfa45526bbdee4a5 | |
parent | cf96a91b69d6d9c8d8f8db3e3eadaa24d25d5f32 (diff) | |
download | qt-creator-9656eb9e7a13213c51a9674a50f710b02abbe124.tar.gz |
QmlJS: Fix more invalid M325 cases
Fixes: QTCREATORBUG-27380
Change-Id: I76d1ef3d2f2a4cc9d930a006ecb3b564efea3fbc
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
-rw-r--r-- | src/libs/qmljs/qmljscheck.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/check/equality-checks.qml | 6 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index d9fe7df36c..519706c326 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -1306,7 +1306,17 @@ static bool isStringValue(const Value *value) if (value->asStringValue()) return true; if (auto obj = value->asObjectValue()) - return obj->className() == "QString" || obj->className() == "string"; + return obj->className() == "QString" || obj->className() == "string" || obj->className() == "String"; + + return false; +} + +static bool isBooleanValue(const Value *value) +{ + if (value->asBooleanValue()) + return true; + if (auto obj = value->asObjectValue()) + return obj->className() == "boolean" || obj->className() == "Boolean"; return false; } @@ -1324,6 +1334,8 @@ static bool strictCompareConstant(const Value *lhs, const Value *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()) diff --git a/tests/auto/qml/codemodel/check/equality-checks.qml b/tests/auto/qml/codemodel/check/equality-checks.qml index 1a2c1f7580..9355142df4 100644 --- a/tests/auto/qml/codemodel/check/equality-checks.qml +++ b/tests/auto/qml/codemodel/check/equality-checks.qml @@ -139,6 +139,12 @@ Rectangle { if (nObj === 1) {} if (nNum === 1) {} + var bObj = Boolean(1 > 0); + if (bObj === b) {} + + var sBool = String(b); + if (sBool === s) {} + } ListView { |