diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-12-17 11:21:35 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-12-17 12:43:14 +0100 |
commit | 0ea14fa1266a00c4102445021f46c042706c963a (patch) | |
tree | ecf08fb15e60d435d0e91533b05892fec8c2b47a /src/qmlcompiler/qqmljscodegenerator.cpp | |
parent | f6294b7938c221974cdf3a39d7d71addf5b08f6b (diff) |
QmlCompiler: Don't try to get attached objects for non-QObject*
We might end up in this situation if we don't know enough about the
base of the attached lookup. This would generate invalid C++ code.
Pick-to: 6.2 6.3
Change-Id: I210077388d0d1d0d4e9454bd3ba3792af9b42049
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljscodegenerator.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index a3cd7cdd91..30d6bc42fb 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -971,7 +971,18 @@ void QQmlJSCodeGenerator::generate_GetLookup(int index) const QString namespaceString = m_state.accumulatorIn.isImportNamespace() ? QString::number(m_state.accumulatorIn.importNamespace()) : u"QQmlPrivate::AOTCompiledContext::InvalidStringId"_qs; + const auto storedType = m_state.accumulatorIn.storedType(); + const bool isReferenceType + = (storedType->accessSemantics() == QQmlJSScope::AccessSemantics::Reference); if (m_state.accumulatorOut.variant() == QQmlJSRegisterContent::ObjectAttached) { + if (!isReferenceType) { + // This can happen on incomplete type information. We contextually know that the + // type must be a QObject, but we cannot construct the inheritance chain. Then we + // store it in a generic type. Technically we could even convert it to QObject*, but + // that would be expensive. + reject(u"attached object for non-QObject type"_qs); + } + const QString lookup = u"aotContext->loadAttachedLookup("_qs + indexString + u", "_qs + use(m_state.accumulatorVariableIn) + u", &"_qs + m_state.accumulatorVariableOut + u')'; @@ -991,10 +1002,6 @@ void QQmlJSCodeGenerator::generate_GetLookup(int index) Q_ASSERT(m_state.accumulatorOut.isProperty()); - const auto storedType = m_state.accumulatorIn.storedType(); - const bool isReferenceType - = (storedType->accessSemantics() == QQmlJSScope::AccessSemantics::Reference); - const QQmlJSScope::ConstPtr out = m_state.accumulatorOut.storedType(); if (isReferenceType) { m_body += u"{\n"_qs; |