From 91c6d455595d245445f28d6d1c27c4f2710ef3c3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 19 Oct 2022 14:35:24 +0200 Subject: QmlCompiler: Allow lists as arguments to methods Since lists are allowed as property types, you should be able to pass them as arguments to methods, too. For now we only handle QML-defined methods, implemented by adding JavaScript functions to your QML elements. The usual type coercion rules apply if you pass JavaScript arrays to such methods. That is, it usually works. We now resolve properties with the "list" flag to their actual types (QQmlListProperty or QList) already when populating the QQmlJSScope, and store the list types as members of QQmlJSScope rather than as a special map in QQmlJSTypeResolver. This allows us to do the same to lists passed as arguments and simplifies some of the type analysis. Fixes: QTBUG-107171 Change-Id: Idf71ccdc1d59f472c17084a36b5d7879c4d959c0 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/qmlcompiler/qqmljsfunctioninitializer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/qmlcompiler/qqmljsfunctioninitializer.cpp') diff --git a/src/qmlcompiler/qqmljsfunctioninitializer.cpp b/src/qmlcompiler/qqmljsfunctioninitializer.cpp index 54bef282ea..b3c448072c 100644 --- a/src/qmlcompiler/qqmljsfunctioninitializer.cpp +++ b/src/qmlcompiler/qqmljsfunctioninitializer.cpp @@ -206,12 +206,11 @@ QQmlJSCompilePass::Function QQmlJSFunctionInitializer::run( } const auto property = m_objectType->property(propertyName); - function.returnType = property.isList() - ? m_typeResolver->listType(property.type(), QQmlJSTypeResolver::UseQObjectList) - : QQmlJSScope::ConstPtr(property.type()); - - - if (!function.returnType) { + if (const QQmlJSScope::ConstPtr propertyType = property.type()) { + function.returnType = propertyType->isListProperty() + ? m_typeResolver->qObjectListType() + : propertyType; + } else { diagnose(u"Cannot resolve property type %1 for binding on %2"_s.arg( property.typeName(), propertyName), QtWarningMsg, bindingLocation, error); -- cgit v1.2.3