diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-04 15:49:39 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-04 23:30:18 +0000 |
commit | 9bbbd0cb21e2e0e0cfa605cc7785e76990fca8be (patch) | |
tree | 6d4048925b671846510f2ee5c10e288584d1a0bd | |
parent | f5d48eb84a0855b0a9492ee6eb3b2fba8f108889 (diff) |
QmlCompiler: Place code for CmpNeInt in parentheses
Otherwise it will apply the '!' to the first argument.
Fixes: QTBUG-100480
Change-Id: Iaefa25d062ad8bbd9d4278ffeaa52fc53ed417e2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit db6459665c4b4a48db9aefebfe310237e7cc92d9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/notEqualsInt.qml | 15 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 15 |
4 files changed, 33 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 639a832c1e..7a512f5d47 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -1904,8 +1904,8 @@ void QQmlJSCodeGenerator::generate_CmpNeInt(int lhsConst) { INJECT_TRACE_INFO(generate_CmpNeInt); - m_body += m_state.accumulatorVariableOut + u" = !"_qs + eqIntExpression(lhsConst) - + u";\n"_qs; + m_body += m_state.accumulatorVariableOut + u" = !("_qs + eqIntExpression(lhsConst) + + u");\n"_qs; } void QQmlJSCodeGenerator::generate_CmpEq(int lhs) diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index ddbc17e18a..053c3bccc2 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -86,6 +86,7 @@ set(qml_files noQQmlData.qml nonNotifyable.qml noscope.qml + notEqualsInt.qml nullAccess.qml outOfBounds.qml overriddenMember.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/notEqualsInt.qml b/tests/auto/qml/qmlcppcodegen/data/notEqualsInt.qml new file mode 100644 index 0000000000..dc1c68c919 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/notEqualsInt.qml @@ -0,0 +1,15 @@ +import QtQml + +QtObject { + property int someValue: 42 + function foo() { + if (someValue != 0) { + t.text = "Bar"; + } + } + + property QtObject tt: QtObject { + id: t + property string text: "Foo" + } +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 1a63d28bf5..99376491fd 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -116,6 +116,7 @@ private slots: void popContextAfterRet(); void revisions(); void invisibleBase(); + void notEqualsInt(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1738,6 +1739,20 @@ void tst_QmlCppCodegen::invisibleBase() QCOMPARE(qvariant_cast<QObject *>(o->property("n")), o.data()); } +void tst_QmlCppCodegen::notEqualsInt() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/notEqualsInt.qml"_qs)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + QObject *t = qmlContext(o.data())->objectForName(u"t"_qs); + QVERIFY(t); + QCOMPARE(t->property("text").toString(), u"Foo"_qs); + QMetaObject::invokeMethod(o.data(), "foo"); + QCOMPARE(t->property("text").toString(), u"Bar"_qs); +} + void tst_QmlCppCodegen::runInterpreted() { if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER")) |