aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimportvisitor.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2025-07-15 14:57:33 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2025-07-25 09:54:57 +0200
commitc7eaffdea665df1678e11cdf4b512d489fa52378 (patch)
tree527a99dff64f5e1daa16f5f5b0822c671f3dc732 /src/qmlcompiler/qqmljsimportvisitor.cpp
parentd877551e298b44d768f09c7662ef497987dab28b (diff)
QQmlJSImportVisitor: Avoid faulty unknown property warning
In QQmlJSImportVisitor::processPropertyBindingObjects, we can encounter grouped properties. So far, we used the whole compount expression to look up the property. That would of course not find any property. We now instead traverse the individual parts of the name, and look up the property chain correctly on the corresponding types. We adjust the previously added test for unknown duplicate properties to work with _really_ unknown properties (that don't exist), and instead use an adjusted version to prove that the example is completely warning free – mirroring the issue from QTBUG-138164 in a more minimal way. Task-number: QTBUG-138498 Task-number: QTBUG-138164 Pick-to: 6.10 Change-Id: I75d17c3c412159f3f6da082f54d99bdf6b3b08e4 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsimportvisitor.cpp')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index c86a358503..eda3a209fd 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -890,6 +890,28 @@ void QQmlJSImportVisitor::processMethodTypes()
}
}
+// TODO: We should investigate whether bindings shouldn't resolve this earlier by themselves
+/*!
+\internal
+Resolves \a possiblyGroupedProperty on a type represented by \a scope.
+possiblyGroupedProperty can be either a simple name, or a grouped property ("foo.bar.baz")
+In the latter case, we resolve the "head" to a property, and then continue with the tail on
+the properties' type.
+We don't handle ids here
+ */
+static QQmlJSMetaProperty resolveProperty(const QString &possiblyGroupedProperty, QQmlJSScope::ConstPtr scope)
+{
+ QQmlJSMetaProperty property;
+ for (QStringView propertyName: possiblyGroupedProperty.tokenize(u".")) {
+ property = scope->property(propertyName.toString());
+ if (property.isValid())
+ scope = property.type();
+ else
+ return property;
+ }
+ return property;
+}
+
void QQmlJSImportVisitor::processPropertyBindingObjects()
{
QSet<std::pair<QQmlJSScope::Ptr, QString>> foundLiterals;
@@ -940,7 +962,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects()
continue;
}
- QQmlJSMetaProperty property = objectBinding.scope->property(propertyName);
+ QQmlJSMetaProperty property = resolveProperty(propertyName, objectBinding.scope);
if (!property.isValid()) {
warnMissingPropertyForBinding(propertyName, objectBinding.location);