diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-06-02 13:51:42 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-06-05 15:35:28 +0000 |
commit | 9e90ea9f616c76d762cabd0bb3ed36fa94309295 (patch) | |
tree | 5574420320e61a1511463bb5774bef1a828fadf1 | |
parent | 544f50597ae3f1d837670c9c27a1e1467396008f (diff) |
QtQml: Recognize local inline components when clearing property caches
Otherwise we may later hit an assert when trying to re-create the
property caches for types with mismatched checksums.
Amends commit 2d7fe23b41aa3fd719b7bc8aa585ab799e4a0c39.
Change-Id: I948f81381e32fff4c5769f6fd51cc59796e2094a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 068fa04c266f774c78915e005bd627df7ecc3150)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/qml/qqmltypedata.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp | 35 |
2 files changed, 36 insertions, 9 deletions
diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index c119452e0f..662a7904d9 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -467,8 +467,16 @@ void QQmlTypeData::done() m_compiledData->resolvedTypes.clear(); // ... but we don't want the property caches we've created for the broken CU. for (QV4::ResolvedTypeReference *ref: std::as_const(resolvedTypeCache)) { - if (ref->compilationUnit() != m_compiledData) + const auto compilationUnit = ref->compilationUnit(); + if (compilationUnit.isNull()) { + // Inline component references without CU belong to the surrounding CU. + // We have to clear them. Inline component references to other documents + // have a CU. + if (!ref->type().isInlineComponentType()) + continue; + } else if (compilationUnit != m_compiledData) { continue; + } ref->setTypePropertyCache(QQmlPropertyCache::ConstPtr()); ref->setCompilationUnit(QQmlRefPointer<QV4::ExecutableCompilationUnit>()); } diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index 9fc27c899b..b7737c5a75 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -1046,7 +1046,7 @@ static QString writeTempFile( void tst_qmldiskcache::invalidateSaveLoadCache() { qmlRegisterType<AParent>("Base", 1, 0, "Parent"); - QQmlEngine e; + std::unique_ptr<QQmlEngine> e = std::make_unique<QQmlEngine>(); // If you store a CU to a .qmlc file at run time, the .qmlc file will contain // alias entries with the encodedMetaPropertyIndex pre-resolved. That's in @@ -1054,14 +1054,32 @@ void tst_qmldiskcache::invalidateSaveLoadCache() // a need to recompile the file. QTemporaryDir tempDir; + writeTempFile( + tempDir, QLatin1String("B.qml"), + R"( + import QML + QtObject { + component C: QtObject {} + } + )"); + const QString fileName = writeTempFile( - tempDir, QLatin1String("a.qml"), - "import Base\nParent { id: self; property alias z: self.x }"); + tempDir, QLatin1String("a.qml"), + R"( + import Base + Parent { + id: self + property alias z: self.x + component C: Parent {} + property C c: C {} + property B.C d: B.C {} + } + )"); const QUrl url = QUrl::fromLocalFile(fileName); waitForFileSystem(); { - QQmlComponent a(&e, url); + QQmlComponent a(e.get(), url); QVERIFY2(a.isReady(), qPrintable(a.errorString())); QScopedPointer<QObject> ao(a.create()); QVERIFY(!ao.isNull()); @@ -1075,12 +1093,13 @@ void tst_qmldiskcache::invalidateSaveLoadCache() QVERIFY2(oldUnit->loadFromDisk(url, QFileInfo(fileName).lastModified(), &errorString), qPrintable(errorString)); // Produce a checksum mismatch. - e.clearComponentCache(); + e->clearComponentCache(); qmlClearTypeRegistrations(); qmlRegisterType<BParent>("Base", 1, 0, "Parent"); + e = std::make_unique<QQmlEngine>(); { - QQmlComponent b(&e, url); + QQmlComponent b(e.get(), url); QVERIFY2(b.isReady(), qPrintable(b.errorString())); QScopedPointer<QObject> bo(b.create()); QVERIFY(!bo.isNull()); @@ -1092,7 +1111,7 @@ void tst_qmldiskcache::invalidateSaveLoadCache() // the above test will not test the save/load cache anymore. Therefore, in order to make really // sure that we get a new CU that invalidates the save/load cache, modify the file in place. - e.clearComponentCache(); + e->clearComponentCache(); { QFile file(fileName); file.open(QIODevice::WriteOnly | QIODevice::Append); @@ -1101,7 +1120,7 @@ void tst_qmldiskcache::invalidateSaveLoadCache() waitForFileSystem(); { - QQmlComponent b(&e, url); + QQmlComponent b(e.get(), url); QVERIFY2(b.isReady(), qPrintable(b.errorString())); QScopedPointer<QObject> bo(b.create()); QVERIFY(!bo.isNull()); |