From 0cee1a4942764f2a7829606c43681d845817d01b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 30 Nov 2021 14:39:48 +0100 Subject: Qml: Don't crash when as-casting to type with errors Such types don't have a compilation unit, but we still know their names. Fixes: QTBUG-98792 Change-Id: I2db8dea3a5a02ec1492f7f7a054fd3ad4c6ad69a Reviewed-by: Fabian Kosmale Reviewed-by: Mitch Curtis (cherry picked from commit e0cd201e91ae64b9c03e0128cd17656b00611fbb) --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp') diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index ac6634290a..92d0069ce4 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -343,6 +343,8 @@ private slots: void bindingAliasToComponentUrl(); void badGroupedProperty(); + void objectAsBroken(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -5951,6 +5953,24 @@ void tst_qqmllanguage::badGroupedProperty() .arg(url.toString())); } +void tst_qqmllanguage::objectAsBroken() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("asBroken.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer o(c.create()); + QVERIFY(!o.isNull()); + QVariant selfAsBroken = o->property("selfAsBroken"); + QVERIFY(selfAsBroken.isValid()); + + // 5.15 doesn't enforce type annotation. So the "as" cast succeeds even though + // the target type cannot be resolved. + QCOMPARE(selfAsBroken.value(), o.data()); + + QQmlComponent b(&engine, testFileUrl("Broken.qml")); + QVERIFY(b.isError()); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3