diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-01-17 11:40:44 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-18 21:07:33 +0000 |
commit | 83b22abcacb5704b94f5003d6242e42417b5c901 (patch) | |
tree | dc7076d3d48744ff4604d015294b61bf24e245ee /tests | |
parent | 838ad1a8d0e9ea4eb62c2428d57b54df4d860c32 (diff) |
QmlCompiler: Handle context push/pop in dead code
Otherwise we end up with unmatched curly braces in the generated code.
Change-Id: I4c24d4062a8ed54cd6a9ecb43dfd2b5d0a26c9e1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
(cherry picked from commit 6a54c6013d9037f5c75d47f5e03d6871591e53b2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/popContextAfterRet.qml | 15 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 18 |
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 59386c33ef..31709b46ea 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -91,6 +91,7 @@ set(qml_files ownProperty.qml page.qml parentProp.qml + popContextAfterRet.qml pressAndHoldButton.qml registerelimination.qml scopeVsObject.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/popContextAfterRet.qml b/tests/auto/qml/qmlcppcodegen/data/popContextAfterRet.qml new file mode 100644 index 0000000000..cde9e054d3 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/popContextAfterRet.qml @@ -0,0 +1,15 @@ +pragma Strict +import QtQml + +QtObject { + id: root + property int stackViewDepth: 0 + onStackViewDepthChanged: { + if (stackViewDepth > 1) { + root.objectName = "backgroundBlur" + return true + } + root.objectName = "backgroundImage" + return false + } +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 5366224fd5..97344ceeb3 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -113,6 +113,7 @@ private slots: void flushBeforeCapture(); void unknownAttached(); void variantlist(); + void popContextAfterRet(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1696,6 +1697,23 @@ void tst_QmlCppCodegen::variantlist() QCOMPARE(things[1].toInt(), 30); } +void tst_QmlCppCodegen::popContextAfterRet() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/popContextAfterRet.qml"_qs)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + + QCOMPARE(o->objectName(), QString()); + o->setProperty("stackViewDepth", 1); + QCOMPARE(o->objectName(), u"backgroundImage"_qs); + o->setProperty("stackViewDepth", 2); + QCOMPARE(o->objectName(), u"backgroundBlur"_qs); + o->setProperty("stackViewDepth", 1); + QCOMPARE(o->objectName(), u"backgroundImage"_qs); +} + void tst_QmlCppCodegen::runInterpreted() { if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER")) |