From 47a1b9fabab20d363d74595677bb2aec09323510 Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Fri, 30 Apr 2021 13:12:26 +0200 Subject: [PATCH] qmllint: Support aliases to lists Previously when resolving aliases all types of additional type information from the target was not copied over into the alias (writability, whether the property is a list etc.). The alias should now accurately reflect the original property's type information. Change-Id: I15078071716590f6a0e6262b8ad40ee946fe7da5 Reviewed-by: Ulf Hermann --- src/qmlcompiler/qqmljsimportvisitor.cpp | 7 +++++++ tests/auto/qml/qmllint/data/AliasListType.qml | 7 +++++++ tests/auto/qml/qmllint/data/aliasToList.qml | 6 ++++++ tests/auto/qml/qmllint/tst_qmllint.cpp | 1 + 4 files changed, 21 insertions(+) create mode 100644 tests/auto/qml/qmllint/data/AliasListType.qml create mode 100644 tests/auto/qml/qmllint/data/aliasToList.qml diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 0f5c308819..e3ecd54714 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -137,6 +137,7 @@ void QQmlJSImportVisitor::resolveAliases() QStringList components = property.typeName().split(u'.'); QQmlJSScope::ConstPtr type; + QQmlJSMetaProperty targetProperty; // The first component has to be an ID. Find the object it refers to. const auto it = m_scopesById.find(components.takeFirst()); @@ -153,6 +154,7 @@ void QQmlJSImportVisitor::resolveAliases() if (!target.type() && target.isAlias()) doRequeue = true; type = target.type(); + targetProperty = target; } } @@ -163,6 +165,11 @@ void QQmlJSImportVisitor::resolveAliases() .arg(property.propertyName()), Log_Alias, object->sourceLocation()); } else { property.setType(type); + // Copy additional property information from target + property.setIsList(targetProperty.isList()); + property.setIsWritable(targetProperty.isWritable()); + property.setIsPointer(targetProperty.isPointer()); + if (const QString internalName = type->internalName(); !internalName.isEmpty()) property.setTypeName(internalName); } diff --git a/tests/auto/qml/qmllint/data/AliasListType.qml b/tests/auto/qml/qmllint/data/AliasListType.qml new file mode 100644 index 0000000000..bdefa1d35f --- /dev/null +++ b/tests/auto/qml/qmllint/data/AliasListType.qml @@ -0,0 +1,7 @@ +import QtQuick 2.15 + +Item { + Item { id: item } + + default property alias content: item.children +} diff --git a/tests/auto/qml/qmllint/data/aliasToList.qml b/tests/auto/qml/qmllint/data/aliasToList.qml new file mode 100644 index 0000000000..890bb9eeda --- /dev/null +++ b/tests/auto/qml/qmllint/data/aliasToList.qml @@ -0,0 +1,6 @@ +import QtQuick 2.15 + +AliasListType { + Item {} + Item {} +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 89e535ac2e..48e4210f9c 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -748,6 +748,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("QtQuick.Window 2.1") << QStringLiteral("qtquickWindow21.qml"); QTest::newRow("attachedTypeIndirect") << QStringLiteral("attachedTypeIndirect.qml"); QTest::newRow("objectArray") << QStringLiteral("objectArray.qml"); + QTest::newRow("aliasToList") << QStringLiteral("aliasToList.qml"); } void TestQmllint::cleanQmlCode()