aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-09-24 13:49:42 +0200
committerUlf Hermann <ulf.hermann@qt.io>2024-09-25 21:24:12 +0200
commitdea8e38d95508acd67da997d0c2a9c91ef1bc887 (patch)
treeda873c76e6037ecd061bd7d7724966b8ccf58032 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent724c48f60a5ffdcd95f99863e215185d05f47a59 (diff)
QmlCompiler: Do not miscompile ID lookups in invalid types
If we cannot resolve a type, we need to assume that all its properties are components and assign separate contexts to all inner objects. Otherwise, if one of them actually is, the attempt to resolve it at run time will crash. Pick-to: 6.8 Fixes: QTBUG-129281 Change-Id: Ic34b5308accdd93f6797ee39fcd56040cf86b1ce Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index c1ab9476a9..eab0a70abd 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -130,6 +130,7 @@ private slots:
void infinities();
void infinitiesToInt();
void innerObjectNonShadowable();
+ void insertContextOnInvalidType();
void intEnumCompare();
void intOverflow();
void intToEnum();
@@ -2475,6 +2476,36 @@ void tst_QmlCppCodegen::innerObjectNonShadowable()
QCOMPARE(rootObject->objectName(), u"foo"_s);
}
+class HandleHandler : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QQmlComponent *handle MEMBER m_handle)
+
+private:
+ QQmlComponent *m_handle = nullptr;
+};
+
+void tst_QmlCppCodegen::insertContextOnInvalidType()
+{
+ qmlRegisterType<HandleHandler>("Handlerei", 1, 0, "HandleHandler");
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/insertContextOnInvalidType.qml"_s));
+
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ "qrc:/qt/qml/TestTypes/insertContextOnInvalidType.qml:5: "
+ "ReferenceError: handleDelegate is not defined");
+ QScopedPointer<QObject> rootObject(component.create());
+ QVERIFY(rootObject);
+
+ const char *outter = "handleDelegateOutter";
+ QVERIFY(rootObject->metaObject()->indexOfProperty(outter) != -1);
+ QVERIFY(!rootObject->property(outter).isValid());
+}
+
void tst_QmlCppCodegen::intEnumCompare()
{
QQmlEngine engine;