Fix restoring of local aliases from disk cache

Local aliases are always "resolved". We must be careful not to access
the same field in the union otherwise and mistake it as property index.

Change-Id: I6369cdba145a62dcdaa10d8f4ee84bfa3cbfa0e3
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Simon Hausmann 2016-08-05 21:10:17 +02:00
parent 8d1bae4c0f
commit a3aad1a470
2 changed files with 47 additions and 0 deletions

View File

@ -567,6 +567,9 @@ inline void QQmlPropertyCacheAliasCreator<ObjectContainer>::appendAliasPropertie
const int targetObjectIndex = objectForId(component, alias->targetObjectId);
Q_ASSERT(targetObjectIndex >= 0);
if (alias->aliasToLocalAlias)
continue;
if (alias->encodedMetaPropertyIndex == -1)
continue;

View File

@ -51,6 +51,7 @@ private slots:
void basicVersionChecks();
void recompileAfterChange();
void fileSelectors();
void localAliases();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@ -485,6 +486,49 @@ void tst_qmldiskcache::fileSelectors()
}
}
void tst_qmldiskcache::localAliases()
{
QQmlEngine engine;
TestCompiler testCompiler(&engine);
QVERIFY(testCompiler.tempDir.isValid());
const QByteArray contents = QByteArrayLiteral("import QtQml 2.0\n"
"QtObject {\n"
" id: root\n"
" property int prop: 100\n"
" property alias dummy1: root.prop\n"
" property alias dummy2: root.prop\n"
" property alias dummy3: root.prop\n"
" property alias dummy4: root.prop\n"
" property alias dummy5: root.prop\n"
" property alias foo: root.prop\n"
" property alias bar: root.foo\n"
"}");
{
testCompiler.clearCache();
QVERIFY2(testCompiler.compile(contents), qPrintable(testCompiler.lastErrorString));
QVERIFY2(testCompiler.verify(), qPrintable(testCompiler.lastErrorString));
}
{
CleanlyLoadingComponent component(&engine, testCompiler.testFilePath);
QScopedPointer<QObject> obj(component.create());
QVERIFY(!obj.isNull());
QCOMPARE(obj->property("bar").toInt(), 100);
}
engine.clearComponentCache();
{
CleanlyLoadingComponent component(&engine, testCompiler.testFilePath);
QScopedPointer<QObject> obj(component.create());
QVERIFY(!obj.isNull());
QCOMPARE(obj->property("bar").toInt(), 100);
}
}
QTEST_MAIN(tst_qmldiskcache)
#include "tst_qmldiskcache.moc"