From 70a38fc67a5a8e311939b24f386addee642c766a Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 2 Jun 2025 11:54:46 +0200 Subject: [PATCH] QQmlJSScope: Create list type for enums When creating the QQmlJSScopes for enums, we would not resolve their corresponding list type, leading to confused qmllint warnings about the type not being found. Fix this by immediately creating the corresponding list type when an enum tpye is created. Pick-to: 6.10 6.9 6.8 Fixes: QTBUG-137256 Change-Id: Ic0479b19467820838426a6f6fe5288cad62e3ff7 Reviewed-by: Ulf Hermann --- src/qmlcompiler/qqmljsscope.cpp | 1 + .../qmllint/data/EnumList/enumlist.qmltypes | 51 +++++++++++++++++++ tests/auto/qml/qmllint/data/EnumList/qmldir | 2 + tests/auto/qml/qmllint/data/enumListTest.qml | 8 +++ tests/auto/qml/qmllint/tst_qmllint.cpp | 1 + 5 files changed, 63 insertions(+) create mode 100644 tests/auto/qml/qmllint/data/EnumList/enumlist.qmltypes create mode 100644 tests/auto/qml/qmllint/data/EnumList/qmldir create mode 100644 tests/auto/qml/qmllint/data/enumListTest.qml diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp index a43e6a8b24..3dededec9a 100644 --- a/src/qmlcompiler/qqmljsscope.cpp +++ b/src/qmlcompiler/qqmljsscope.cpp @@ -662,6 +662,7 @@ void QQmlJSScope::resolveEnums( enumScope->m_semantics = AccessSemantics::Value; enumScope->m_internalName = self->internalName() + QStringLiteral("::") + it->name(); + resolveList(enumScope, contextualTypes.arrayType()); if (QString alias = it->alias(); !alias.isEmpty() && self->m_enumerations.constFind(alias) == self->m_enumerations.constEnd()) { auto aliasScope = QQmlJSScope::clone(enumScope); diff --git a/tests/auto/qml/qmllint/data/EnumList/enumlist.qmltypes b/tests/auto/qml/qmllint/data/EnumList/enumlist.qmltypes new file mode 100644 index 0000000000..031f7406f6 --- /dev/null +++ b/tests/auto/qml/qmllint/data/EnumList/enumlist.qmltypes @@ -0,0 +1,51 @@ +import QtQuick.tooling 1.2 + +// This file describes the plugin-supplied types contained in the library. +// It is used for QML tooling purposes only. +// +// This file was auto-generated by qmltyperegistrar. + +Module { + Component { + file: "mycustomtype.h" + name: "MyCustomType" + accessSemantics: "reference" + prototype: "QObject" + exports: ["EnumProperty/MyCustomType 1.0"] + exportMetaObjectRevisions: [256] + Property { + name: "requiredConditions" + type: "Org::Company::Configuration::Condition" + isList: true + read: "getRequiredConditions" + write: "setRequiredConditions" + notify: "requiredConditionsChanged" + index: 0 + } + Property { + name: "enablerConditions" + type: "int" + isList: true + read: "getEnablerConditions" + write: "setEnablerConditions" + notify: "enablerConditionsChanged" + index: 1 + } + Signal { name: "requiredConditionsChanged" } + Signal { name: "enablerConditionsChanged" } + } + Component { + file: "conditiontypes.h" + name: "Org::Company::Configuration" + accessSemantics: "none" + exports: ["EnumProperty/Configuration 1.0"] + isCreatable: false + enforcesScopedEnums: true + exportMetaObjectRevisions: [256] + Enum { + name: "Condition" + isScoped: true + values: ["A", "B", "C", "D"] + } + } +} diff --git a/tests/auto/qml/qmllint/data/EnumList/qmldir b/tests/auto/qml/qmllint/data/EnumList/qmldir new file mode 100644 index 0000000000..fd0d54437b --- /dev/null +++ b/tests/auto/qml/qmllint/data/EnumList/qmldir @@ -0,0 +1,2 @@ +module EnumList +typeinfo enumlist.qmltypes diff --git a/tests/auto/qml/qmllint/data/enumListTest.qml b/tests/auto/qml/qmllint/data/enumListTest.qml new file mode 100644 index 0000000000..5ba6dfe4cc --- /dev/null +++ b/tests/auto/qml/qmllint/data/enumListTest.qml @@ -0,0 +1,8 @@ +import EnumList +import QtQml + +MyCustomType { + id: myType + requiredConditions: [Configuration.Condition.A, Configuration.Condition.C] +} + diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index bfc8d81c7e..12f684be67 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -1975,6 +1975,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("dontConfuseMemberPrintWithGlobalPrint") << QStringLiteral("findMemberPrint.qml"); QTest::newRow("duplicateQmldirImport") << QStringLiteral("qmldirImport/duplicate.qml"); QTest::newRow("enumFromQtQml") << QStringLiteral("enumFromQtQml.qml"); + QTest::newRow("enumList") << QStringLiteral("enumListTest.qml"); QTest::newRow("enumProperty") << QStringLiteral("enumProperty.qml"); QTest::newRow("enumsOfScrollBar") << QStringLiteral("enumsOfScrollBar.qml"); QTest::newRow("esmodule") << QStringLiteral("esmodule.mjs");