aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-10-21 14:06:22 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-11-05 00:02:39 +0000
commit5080d05609b40cff0d747023453fb0c6e692690e (patch)
treee79c08cae71081d3c9958191dcdb8f7f25e3ac02
parentf7aceb6ee9e33312a29360cafe1ca1d7e8ad1e57 (diff)
QmlCompiler: Resolve regular group properties like generalized ones
They are mostly the same. We only need to search the local properties rather than the IDs for the regular group properties. This allows us to resolve group properties on aliases since aliases get resolved before group properties. Fixes: QTBUG-128632 Change-Id: I6f77a65499dd6bec29269f7b0974180fa76a749e Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 8c2fa03305c344c6a65d428ba1e9c05c2e65c281) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp50
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor_p.h3
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp2
-rw-r--r--src/qmlcompiler/qqmljsscope_p.h2
-rw-r--r--tests/auto/qml/qmllint/data/aliasGroup.qml20
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
6 files changed, 59 insertions, 19 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index b9251ef0cf..7e259b3ac3 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -239,12 +239,12 @@ bool QQmlJSImportVisitor::isTypeResolved(const QQmlJSScope::ConstPtr &type)
return isTypeResolved(type, handleUnresolvedType);
}
-static bool mayBeUnresolvedGeneralizedGroupedProperty(const QQmlJSScope::ConstPtr &scope)
+static bool mayBeUnresolvedGroupedProperty(const QQmlJSScope::ConstPtr &scope)
{
return scope->scopeType() == QQmlSA::ScopeType::GroupedPropertyScope && !scope->baseType();
}
-void QQmlJSImportVisitor::resolveAliasesAndIds()
+void QQmlJSImportVisitor::resolveAliases()
{
QQueue<QQmlJSScope::Ptr> objects;
objects.enqueue(m_exportedRootScope);
@@ -334,20 +334,8 @@ void QQmlJSImportVisitor::resolveAliasesAndIds()
}
const auto childScopes = object->childScopes();
- for (const auto &childScope : childScopes) {
- if (mayBeUnresolvedGeneralizedGroupedProperty(childScope)) {
- const QString name = childScope->internalName();
- if (object->isNameDeferred(name)) {
- const QQmlJSScope::ConstPtr deferred = m_scopesById.scope(name, childScope);
- if (!deferred.isNull()) {
- QQmlJSScope::resolveGeneralizedGroup(
- childScope, deferred, m_rootScopeImports.contextualTypes(),
- &m_usedTypes);
- }
- }
- }
+ for (const auto &childScope : childScopes)
objects.enqueue(childScope);
- }
if (doRequeue)
requeue.enqueue(object);
@@ -371,6 +359,35 @@ void QQmlJSImportVisitor::resolveAliasesAndIds()
}
}
+void QQmlJSImportVisitor::resolveGroupProperties()
+{
+ QQueue<QQmlJSScope::Ptr> objects;
+ objects.enqueue(m_exportedRootScope);
+
+ while (!objects.isEmpty()) {
+ const QQmlJSScope::Ptr object = objects.dequeue();
+ const auto childScopes = object->childScopes();
+ for (const auto &childScope : childScopes) {
+ if (mayBeUnresolvedGroupedProperty(childScope)) {
+ const QString name = childScope->internalName();
+ if (object->isNameDeferred(name)) {
+ const QQmlJSScope::ConstPtr deferred = m_scopesById.scope(name, childScope);
+ if (!deferred.isNull()) {
+ QQmlJSScope::resolveGroup(
+ childScope, deferred, m_rootScopeImports.contextualTypes(),
+ &m_usedTypes);
+ }
+ } else if (const QQmlJSScope::ConstPtr propType = object->property(name).type()) {
+ QQmlJSScope::resolveGroup(
+ childScope, propType, m_rootScopeImports.contextualTypes(),
+ &m_usedTypes);
+ }
+ }
+ objects.enqueue(childScope);
+ }
+ }
+}
+
QString QQmlJSImportVisitor::implicitImportDirectory(
const QString &localFile, QQmlJSResourceFileMapper *mapper)
{
@@ -461,7 +478,8 @@ void QQmlJSImportVisitor::endVisit(UiProgram *)
checkDeprecation(scope);
}
- resolveAliasesAndIds();
+ resolveAliases();
+ resolveGroupProperties();
for (const auto &scope : m_objectDefinitionScopes)
checkGroupedAndAttachedScopes(scope);
diff --git a/src/qmlcompiler/qqmljsimportvisitor_p.h b/src/qmlcompiler/qqmljsimportvisitor_p.h
index 015f846638..3684492b03 100644
--- a/src/qmlcompiler/qqmljsimportvisitor_p.h
+++ b/src/qmlcompiler/qqmljsimportvisitor_p.h
@@ -352,7 +352,8 @@ private:
const QQmlJSScope::ConstPtr &signalScope, const QQmlJS::SourceLocation &location,
const QString &handlerName, const QStringList &handlerParameters);
void importBaseModules();
- void resolveAliasesAndIds();
+ void resolveAliases();
+ void resolveGroupProperties();
void handleIdDeclaration(QQmlJS::AST::UiScriptBinding *scriptBinding);
void visitFunctionExpressionHelper(QQmlJS::AST::FunctionExpression *fexpr);
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp
index d6b8b62048..2094372e68 100644
--- a/src/qmlcompiler/qqmljsscope.cpp
+++ b/src/qmlcompiler/qqmljsscope.cpp
@@ -703,7 +703,7 @@ void QQmlJSScope::resolveList(const QQmlJSScope::Ptr &self, const QQmlJSScope::C
self->m_listType = listType;
}
-void QQmlJSScope::resolveGeneralizedGroup(
+void QQmlJSScope::resolveGroup(
const Ptr &self, const ConstPtr &baseType,
const QQmlJS::ContextualTypes &contextualTypes, QSet<QString> *usedTypes)
{
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h
index e34346b2b7..e5104a287b 100644
--- a/src/qmlcompiler/qqmljsscope_p.h
+++ b/src/qmlcompiler/qqmljsscope_p.h
@@ -450,7 +450,7 @@ public:
QSet<QString> *usedTypes = nullptr);
static void resolveList(
const QQmlJSScope::Ptr &self, const QQmlJSScope::ConstPtr &arrayType);
- static void resolveGeneralizedGroup(
+ static void resolveGroup(
const QQmlJSScope::Ptr &self, const QQmlJSScope::ConstPtr &baseType,
const QQmlJS::ContextualTypes &contextualTypes,
QSet<QString> *usedTypes = nullptr);
diff --git a/tests/auto/qml/qmllint/data/aliasGroup.qml b/tests/auto/qml/qmllint/data/aliasGroup.qml
new file mode 100644
index 0000000000..b3b59251a2
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/aliasGroup.qml
@@ -0,0 +1,20 @@
+import QtQml
+
+QtObject {
+ id: root
+
+ property QtObject o: SampleDataStoreManagerSettingsSection {
+ contentControl.contentItem: QtObject { objectName: "a" }
+ }
+
+ component SampleDataStoreManagerSettingsSection: QtObject {
+ property alias contentControl: sectionContentItem
+
+ property QtObject o: QtObject {
+ id: sectionContentItem
+ property QtObject contentItem
+
+ }
+ }
+}
+
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 1eb80b288d..e029f114ab 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -1441,6 +1441,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("overlay") << QStringLiteral("overlayFromControls.qml");
#endif
QTest::newRow("thisObject") << QStringLiteral("thisObject.qml");
+ QTest::newRow("aliasGroup") << QStringLiteral("aliasGroup.qml");
}
void TestQmllint::cleanQmlCode()