diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-03 14:45:49 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-14 12:38:10 +0100 |
commit | 89b7e8def608906d541e0adfc559a1eedf9358cf (patch) | |
tree | 305c2ee189fee1f4ee12db47f4c17fbf62c42ead /src/qmlcompiler/qqmljscodegenerator.cpp | |
parent | 8be258b7e69fdc94a4a6a63d1964d96f8dfcb50e (diff) |
QmlCompiler: Allow assigning empty lists to list properties
Generate an empty list when creating a list with 0 elements.
Task-number: QTBUG-100157
Change-Id: I3b0fe0b737a8ec5257785ae32231f4b687d3b204
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, 13 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 667dbc2833..f8d585002b 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -139,6 +139,7 @@ QQmlJSAotFunction QQmlJSCodeGenerator::run( const QQmlJSScope::ConstPtr storedType = registerTypeIt.key(); if (storedType == m_typeResolver->nullType() + || storedType == m_typeResolver->emptyListType() || storedType == m_typeResolver->voidType()) { continue; } @@ -1674,9 +1675,9 @@ void QQmlJSCodeGenerator::generate_DeclareVar(int varName, int isDeletable) void QQmlJSCodeGenerator::generate_DefineArray(int argc, int args) { - Q_UNUSED(argc); Q_UNUSED(args); - reject(u"DefineArray"_qs); + if (argc > 0) + reject(u"DefineArray"_qs); } void QQmlJSCodeGenerator::generate_DefineObjectLiteral(int internalClassId, int argc, int args) @@ -2491,6 +2492,16 @@ QString QQmlJSCodeGenerator::conversion(const QQmlJSScope::ConstPtr &from, reject(u"Conversion from null to %1"_qs.arg(to->internalName())); } + if (from == m_typeResolver->emptyListType()) { + if (to->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence) + return castTargetName(to) + u"()"_qs; + if (to == m_typeResolver->varType()) + return u"QVariant(QVariantList())"_qs; + if (to == from) + return QString(); + reject(u"Conversion from empty list to %1"_qs.arg(to->internalName())); + } + if (from == to) return variable; |