QmlCompiler: Handle ID lookups of incomplete types correctly

Incomplete types are generally stored in some wrapper type. We cannot
just assign to the accumulator. Also, we already know whether we have an
ID lookup there. No need to determine it again.

Pick-to: 6.2 6.3
Change-Id: I1f9fd9f147c44975df33fe862523987d8e711905
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2022-01-21 13:14:20 +01:00
parent 3fc68053db
commit 3747c02fe6
4 changed files with 24 additions and 3 deletions

View File

@ -673,10 +673,10 @@ void QQmlJSCodeGenerator::generate_LoadQmlContextPropertyLookup(int index)
}
const QString indexString = QString::number(index);
const QQmlJSScope::ConstPtr scopeForId = m_typeResolver->scopeForId(name, m_function->qmlScope);
if (!scopeForId.isNull()) {
if (m_state.accumulatorOut.variant() == QQmlJSRegisterContent::ObjectById) {
const QString lookup = u"aotContext->loadContextIdLookup("_qs
+ indexString + u", &"_qs + m_state.accumulatorVariableOut + u')';
+ indexString + u", "_qs
+ contentPointer(m_state.accumulatorOut, m_state.accumulatorVariableOut) + u')';
const QString initialization = u"aotContext->initLoadContextIdLookup("_qs
+ indexString + u')';
generateLookup(lookup, initialization);

View File

@ -67,6 +67,7 @@ set(qml_files
immediateQuit.qml
imports/QmlBench/Globals.qml
importsFromImportPath.qml
invisibleBase.qml
intEnumCompare.qml
intOverflow.qml
interactive.qml

View File

@ -0,0 +1,9 @@
import TestTypes
import QtQml
Nasty {
id: nasty
property Nasty n: nasty
}

View File

@ -115,6 +115,7 @@ private slots:
void variantlist();
void popContextAfterRet();
void revisions();
void invisibleBase();
};
void tst_QmlCppCodegen::simpleBinding()
@ -1727,6 +1728,16 @@ void tst_QmlCppCodegen::revisions()
QCOMPARE(o->property("gotten").toInt(), 5);
}
void tst_QmlCppCodegen::invisibleBase()
{
QQmlEngine engine;
QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/invisibleBase.qml"_qs));
QVERIFY2(c.isReady(), qPrintable(c.errorString()));
QScopedPointer<QObject> o(c.create());
QVERIFY(o);
QCOMPARE(qvariant_cast<QObject *>(o->property("n")), o.data());
}
void tst_QmlCppCodegen::runInterpreted()
{
if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER"))