From d5e7e3970d7155d93b81e8cd145e6ee51f13ce72 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 8 Sep 2022 17:21:10 +0200 Subject: Qml: Don't crash on bad grouped properties Fixes: QTBUG-106457 Change-Id: Id36b54fd3ed413c0ac49e33e5ea87984d5220aef Reviewed-by: Volker Hilsheimer (cherry picked from commit e061c934d5a6d93493ba2be7b61efdd055d1e164) Reviewed-by: Fabian Kosmale --- src/qml/qml/qqmlpropertycachecreator.cpp | 4 +++- tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml | 10 ++++++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml diff --git a/src/qml/qml/qqmlpropertycachecreator.cpp b/src/qml/qml/qqmlpropertycachecreator.cpp index 5e5a3aa840..fe68337eb3 100644 --- a/src/qml/qml/qqmlpropertycachecreator.cpp +++ b/src/qml/qml/qqmlpropertycachecreator.cpp @@ -115,8 +115,10 @@ bool QQmlBindingInstantiationContext::resolveInstantiatingProperty() return true; } + if (!referencingObjectPropertyCache) + return false; + Q_ASSERT(referencingObjectIndex >= 0); - Q_ASSERT(referencingObjectPropertyCache); Q_ASSERT(instantiatingBinding->propertyNameIndex != 0); bool notInRevision = false; diff --git a/tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml b/tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml new file mode 100644 index 0000000000..1b8ba61725 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml @@ -0,0 +1,10 @@ +import QtQml + +QtObject { + id: testItem + property rect rect + onComplete { + rect.x: 2 + rect.width: 22 + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 4a7a0b4085..e5586d27c9 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -398,6 +398,7 @@ private slots: void uncreatableAttached(); void bindableOnly(); + void badGroupedProperty(); private: QQmlEngine engine; @@ -6921,6 +6922,17 @@ void tst_qqmllanguage::bindableOnly() QCOMPARE(o->objectName(), QStringLiteral("score")); } +void tst_qqmllanguage::badGroupedProperty() +{ + QQmlEngine engine; + const QUrl url = testFileUrl("badGroupedProperty.qml"); + QQmlComponent c(&engine, url); + QVERIFY(c.isError()); + QCOMPARE(c.errorString(), + QStringLiteral("%1:6 Cannot assign to non-existent property \"onComplete\"\n") + .arg(url.toString())); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3