From f6fc35b45b449fe7aaca3237f29393a12fc3f90c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 1 Feb 2021 15:03:19 +0100 Subject: QmlCompiler: Allow for multiple extensions per object Previously, the assumption was that each object could only have a single extension object. As proven by the new qqmllanguage test this is not the case. Each registered object in the type hierarchy can have its own extension. Therefore, adjust the algorithms that generate qmltypes and iterate the extension objects when analyzing them. This leads us to the realization that anonymous types can in fact meaningfully carry extensions and implement interfaces. Adapt qmltyperegistrar accordingly. For the test to compile, however, we need to realize that the class declaring interfaces needs to befriend all potential subclass's QmlInterface structs. Fix that, too. The rabbit hole went deep. Change-Id: Ia451897e927e03b95c3062e829edf1dfcd216613 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 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 454ae59ad3..5e40387ceb 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -347,6 +347,8 @@ private slots: void extendedSingleton(); void qtbug_85932(); + void multiExtension(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -6128,6 +6130,25 @@ void tst_qqmllanguage::qtbug_85932() QCOMPARE(allWarnings.at(1).toString(), warning2); } +void tst_qqmllanguage::multiExtension() +{ + QQmlEngine engine; + QQmlComponent c(&engine); + c.setData("import StaticTest\nMultiExtension {}", QUrl()); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer o(c.create()); + QCOMPARE(o->property("a").toInt(), int('a')); + QCOMPARE(o->property("b").toInt(), int('b')); + QCOMPARE(o->property("p").toInt(), int('p')); + QCOMPARE(o->property("e").toInt(), int('e')); + + // Extension properties override base object properties + QCOMPARE(o->property("c").toInt(), 12); + QCOMPARE(o->property("d").toInt(), 22); + QCOMPARE(o->property("f").toInt(), 31); + QCOMPARE(o->property("g").toInt(), 44); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3