diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-09-28 11:15:27 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-09-28 13:36:21 +0000 |
commit | 95f8cd5632dcb72ec4fa7910099f210ce5f22078 (patch) | |
tree | 14b273e119ed9953523091f6140643f4243c099f | |
parent | 725f7e38ac473668459b25b09d0eb7993dbd9ea2 (diff) |
qqmlimport: Use stable_partition instead of stable_sort
We do not actually need to sort the imports list, we just require that
all inline component imports come before all other imports.
This avoids triggering a MSVC STL debug assertion about the used Compare
function not actually creating a strict ordering.
Fixes: QTBUG-86989
Change-Id: I381852392545287ec02b186fcb4f33be3ae95b33
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 3eb9ee34c06d54ea21fedd3188c60e536a487b1c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/twoInlineComponents.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 30 |
3 files changed, 26 insertions, 14 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index c3f6a9057d..6d4fba0aa4 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -989,8 +989,8 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS typeRecursionDetected = &localTypeRecursionDetected; if (needsSorting()) { - std::stable_sort(imports.begin(), imports.end(), [](QQmlImportInstance *left, QQmlImportInstance *) { - return left->isInlineComponent; + std::stable_partition(imports.begin(), imports.end(), [](QQmlImportInstance *import) { + return import->isInlineComponent; }); setNeedsSorting(false); } diff --git a/tests/auto/qml/qqmllanguage/data/twoInlineComponents.qml b/tests/auto/qml/qqmllanguage/data/twoInlineComponents.qml new file mode 100644 index 0000000000..73cb4cb5b0 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/twoInlineComponents.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +Item { + component IC1: Item {} + component IC2: Item {} +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 187243fbbd..e32fa884a2 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -5557,6 +5557,7 @@ void tst_qqmllanguage::inlineComponent() QFETCH(QUrl, componentUrl); QFETCH(QColor, color); QFETCH(int, width); + QFETCH(bool, checkProperties); QQmlEngine engine; QQmlComponent component(&engine, componentUrl); QScopedPointer<QObject> o(component.create()); @@ -5564,10 +5565,12 @@ void tst_qqmllanguage::inlineComponent() qDebug() << component.errorString(); } QVERIFY(!o.isNull()); - auto icInstance = o->findChild<QObject *>("icInstance"); - QVERIFY(icInstance); - QCOMPARE(icInstance->property("color").value<QColor>(),color); - QCOMPARE(icInstance->property("width").value<qreal>(), width); + if (checkProperties) { + auto icInstance = o->findChild<QObject *>("icInstance"); + QVERIFY(icInstance); + QCOMPARE(icInstance->property("color").value<QColor>(),color); + QCOMPARE(icInstance->property("width").value<qreal>(), width); + } } void tst_qqmllanguage::inlineComponent_data() @@ -5575,18 +5578,21 @@ void tst_qqmllanguage::inlineComponent_data() QTest::addColumn<QUrl>("componentUrl"); QTest::addColumn<QColor>("color"); QTest::addColumn<int>("width"); + QTest::addColumn<bool>("checkProperties"); + + QTest::newRow("Usage from other component") << testFileUrl("inlineComponentUser1.qml") << QColorConstants::Blue << 24 << true; + QTest::newRow("Reexport") << testFileUrl("inlineComponentUser2.qml") << QColorConstants::Svg::green << 24 << true; + QTest::newRow("Usage in same component") << testFileUrl("inlineComponentUser3.qml") << QColorConstants::Blue << 24 << true; - QTest::newRow("Usage from other component") << testFileUrl("inlineComponentUser1.qml") << QColorConstants::Blue << 24; - QTest::newRow("Reexport") << testFileUrl("inlineComponentUser2.qml") << QColorConstants::Svg::green << 24; - QTest::newRow("Usage in same component") << testFileUrl("inlineComponentUser3.qml") << QColorConstants::Blue << 24; + QTest::newRow("Resolution happens at instantiation") << testFileUrl("inlineComponentUser4.qml") << QColorConstants::Blue << 24 << true; + QTest::newRow("Non-toplevel IC is found") << testFileUrl("inlineComponentUser5.qml") << QColorConstants::Svg::red << 24 << true; - QTest::newRow("Resolution happens at instantiation") << testFileUrl("inlineComponentUser4.qml") << QColorConstants::Blue << 24; - QTest::newRow("Non-toplevel IC is found") << testFileUrl("inlineComponentUser5.qml") << QColorConstants::Svg::red << 24; + QTest::newRow("Resolved in correct order") << testFileUrl("inlineComponentOrder.qml") << QColorConstants::Blue << 200 << true; - QTest::newRow("Resolved in correct order") << testFileUrl("inlineComponentOrder.qml") << QColorConstants::Blue << 200; + QTest::newRow("ID resolves correctly") << testFileUrl("inlineComponentWithId.qml") << QColorConstants::Svg::red << 42 << true; + QTest::newRow("Alias resolves correctly") << testFileUrl("inlineComponentWithAlias.qml") << QColorConstants::Svg::lime << 42 << true; - QTest::newRow("ID resolves correctly") << testFileUrl("inlineComponentWithId.qml") << QColorConstants::Svg::red << 42; - QTest::newRow("Alias resolves correctly") << testFileUrl("inlineComponentWithAlias.qml") << QColorConstants::Svg::lime << 42; + QTest::newRow("Two inline components in same do not crash (QTBUG-86989)") << testFileUrl("twoInlineComponents.qml") << QColor() << 0 << false; } void tst_qqmllanguage::inlineComponentReferenceCycle_data() |