From f686bce68fb2d1e1de66642ce20e59bba25670ba Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 5 Nov 2021 14:49:51 +0100 Subject: [PATCH] QmlJS: Soften strict equality check Pt II Disable strict equality check for undefined values as there are too many ways the code model just assumes "undefined" as the information would be present at runtime only or to avoid too complex evaluation. Task-number: QTCREATORBUG-25917 Change-Id: I7c6da04f52ba767c4ef5c21078dc14ac4de86687 Reviewed-by: Fabian Kosmale --- src/libs/qmljs/qmljscheck.cpp | 8 +++++--- tests/auto/qml/codemodel/check/equality-checks.qml | 14 +++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index 38595a8b363..bd5d25834ed 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -1275,6 +1275,9 @@ static bool isIntegerValue(const Value *value) 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 @@ -1283,12 +1286,11 @@ static bool strictCompareConstant(const Value *lhs, const Value *rhs) return false; if (lhs->asBooleanValue() && !rhs->asBooleanValue()) return true; - // attached properties and working at runtime cases may be undefined at evaluation time - if (lhs->asNumberValue() && (!rhs->asNumberValue() && !rhs->asUndefinedValue())) + if (lhs->asNumberValue() && !rhs->asNumberValue()) return true; if (lhs->asStringValue() && !rhs->asStringValue()) return true; - if (lhs->asObjectValue() && (!rhs->asObjectValue() || !rhs->asNullValue() || !rhs->asUndefinedValue())) + if (lhs->asObjectValue() && (!rhs->asObjectValue() || !rhs->asNullValue())) return true; return false; } diff --git a/tests/auto/qml/codemodel/check/equality-checks.qml b/tests/auto/qml/codemodel/check/equality-checks.qml index 0a24cccce9a..1a2c1f7580b 100644 --- a/tests/auto/qml/codemodel/check/equality-checks.qml +++ b/tests/auto/qml/codemodel/check/equality-checks.qml @@ -71,14 +71,14 @@ Rectangle { if (s === s) {} if (s === n) {} // 325 15 17 if (s === N) {} // 325 15 17 - if (s === u) {} // 325 15 17 + if (s === u) {} if (s === b) {} // 325 15 17 if (s === o) {} // 325 15 17 if (s === k) {} if (s !== s) {} if (s !== n) {} // 325 15 17 if (s !== N) {} // 325 15 17 - if (s !== u) {} // 325 15 17 + if (s !== u) {} if (s !== b) {} // 325 15 17 if (s !== o) {} // 325 15 17 if (s !== k) {} @@ -100,19 +100,19 @@ Rectangle { if (N === o) {} // 325 15 17 if (N === k) {} - if (u === s) {} // 325 15 17 + if (u === s) {} if (u === n) {} if (u === N) {} if (u === u) {} - if (u === b) {} // 325 15 17 - if (u === o) {} // 325 15 17 + if (u === b) {} + if (u === o) {} if (u === k) {} if (b === s) {} // 325 15 17 if (b === n) {} // 325 15 17 if (b === N) {} // 325 15 17 - if (b === u) {} // 325 15 17 + if (b === u) {} if (b === b) {} if (b === o) {} // 325 15 17 if (b === k) {} @@ -120,7 +120,7 @@ Rectangle { if (o === s) {} // 325 15 17 if (o === n) {} // 325 15 17 if (o === N) {} // 325 15 17 - if (o === u) {} // 325 15 17 + if (o === u) {} if (o === b) {} // 325 15 17 if (o === o) {} // 325 15 17 if (o === k) {}