From e516ef519b116f27d7ed5387275be27a4215a792 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 1 Feb 2024 16:14:47 +0100 Subject: QtQml: Double-check inline components when type-checking functions Inline components are created speculatively. You can end up with a QQmlType that's not backed by a compilation unit. Pick-to: 6.7 6.6 Fixes: QTBUG-120506 Change-Id: Ie12f0d503ae8d8d238346948981803c1c07e8515 Reviewed-by: Fabian Kosmale --- .../auto/qml/qqmllanguage/data/badICAnnotation.qml | 25 ++++++++++++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 34 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/auto/qml/qqmllanguage/data/badICAnnotation.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmllanguage/data/badICAnnotation.qml b/tests/auto/qml/qqmllanguage/data/badICAnnotation.qml new file mode 100644 index 0000000000..6f0db53f2a --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/badICAnnotation.qml @@ -0,0 +1,25 @@ +import QtQml + +QtObject { + id: self + + function doStuff(status: Binding.NotAnInlineComponent) : int { + return status + } + + function doStuff2(status: InlineComponentBase.IC) : QtObject { + return status + } + + function doStuff3(status: InlineComponentBase.NotIC) : QtObject { + return status + } + + property InlineComponentBase.IC ic: InlineComponentBase.IC {} + + property int a: doStuff(5) + property QtObject b: doStuff2(ic) + property QtObject c: doStuff3(ic) + property QtObject d: doStuff2(self) +} + diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 66246b7a49..ec906e61df 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -443,6 +443,7 @@ private slots: void ambiguousComponents(); void writeNumberToEnumAlias(); + void badInlineComponentAnnotation(); private: QQmlEngine engine; @@ -8512,6 +8513,39 @@ void tst_qqmllanguage::writeNumberToEnumAlias() QCOMPARE(o->property("strokeStyle").toInt(), 1); } +void tst_qqmllanguage::badInlineComponentAnnotation() +{ + QQmlEngine engine; + const QUrl url = testFileUrl("badICAnnotation.qml"); + QQmlComponent c(&engine, testFileUrl("badICAnnotation.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + QTest::ignoreMessage( + QtCriticalMsg, + qPrintable(url.toString() + ":20: 5 should be coerced to void because the function " + "called is insufficiently annotated. The original " + "value is retained. This will change in a future " + "version of Qt.")); + QTest::ignoreMessage( + QtCriticalMsg, + QRegularExpression(":22: IC\\([^\\)]+\\) should be coerced to void because the " + "function called is insufficiently annotated. The original " + "value is retained. This will change in a future version of " + "Qt\\.")); + + QScopedPointer o(c.create()); + QVERIFY(!o.isNull()); + + QCOMPARE(o->property("a").toInt(), 5); + + QObject *ic = o->property("ic").value(); + QVERIFY(ic); + + QCOMPARE(o->property("b").value(), ic); + QCOMPARE(o->property("c").value(), ic); + QCOMPARE(o->property("d").value(), nullptr); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3