diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-07-22 16:32:18 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-07-29 15:22:49 +0200 |
commit | 4580f49fb9867fd0f6cf597a45fbe74b0f5d6a48 (patch) | |
tree | 27d7b50fa31a061857c0dcdda5a91a912075843f | |
parent | 91ce865050b9e017e63ae5b0c54e2d385705d155 (diff) |
qmltc: Acknowledge group/attached properties have objects in QmlIR
Group and attached properties have QmlIR::Objects associated with them.
However, qmltc's object index calculation ignores groups/attached types.
Fix this, making object index calculation aligned for implicit
components
Fixes: QTBUG-104780
Change-Id: I377d3eab714d0e9618ac2ef84c2738b45ad3b6cc
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 2f4935289e99cd5f174316ceb82032d62292bd46)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tests/auto/qml/qmltc/QmltcTests/delegate_context.qml | 1 | ||||
-rw-r--r-- | tools/qmltc/qmltcvisitor.cpp | 24 |
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/delegate_context.qml b/tests/auto/qml/qmltc/QmltcTests/delegate_context.qml index 8dfcbb24b4..33937f48e2 100644 --- a/tests/auto/qml/qmltc/QmltcTests/delegate_context.qml +++ b/tests/auto/qml/qmltc/QmltcTests/delegate_context.qml @@ -7,6 +7,7 @@ Text { ListView { id: listView model: 1 + anchors.fill: parent // QTBUG-104780 delegate: Text { // QV4::CompiledData::Object::IsComponent id: listViewDelegate diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp index 1099dfaae5..8b7f0fdb45 100644 --- a/tools/qmltc/qmltcvisitor.cpp +++ b/tools/qmltc/qmltcvisitor.cpp @@ -472,6 +472,28 @@ void QmltcVisitor::postVisitResolve( qSwap(m_qmlTypesWithQmlBases, filteredQmlTypesWithQmlBases); } + // count QmlIR::Objects in the document - the amount is used to calculate + // object indices of implicit components + int qmlScopeCount = 0; + const auto countQmlScopes = [&](const QQmlJSScope::ConstPtr &scope) { + if (scope->isArrayScope()) // special kind of QQmlJSScope::QMLScope + return; + switch (scope->scopeType()) { + case QQmlJSScope::QMLScope: + case QQmlJSScope::GroupedPropertyScope: + case QQmlJSScope::AttachedPropertyScope: { + ++qmlScopeCount; + break; + } + default: + return; + } + return; + }; + // order doesn't matter (so re-use QQmlJSUtils) + QQmlJSUtils::traverseFollowingQmlIrObjectStructure(m_exportedRootScope, countQmlScopes); + Q_ASSERT(qmlScopeCount >= int(m_qmlTypes.size())); + // figure synthetic indices of QQmlComponent-wrapped types int syntheticCreationIndex = 0; const auto addSyntheticIndex = [&](const QQmlJSScope::ConstPtr &type) { @@ -484,7 +506,7 @@ void QmltcVisitor::postVisitResolve( const auto cppBase = QQmlJSScope::nonCompositeBaseType(type); const bool isComponentBased = (cppBase && cppBase->internalName() == u"QQmlComponent"_s); if (type->isComponentRootElement() && !isComponentBased) { - const int index = int(m_qmlTypes.size()) + syntheticCreationIndex++; + const int index = int(qmlScopeCount) + syntheticCreationIndex++; m_syntheticTypeIndices[type] = index; return true; } |