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 <ulf.hermann@qt.io>
This commit is contained in:
Fabian Kosmale 2025-06-02 11:54:46 +02:00
parent 87d82d734b
commit 70a38fc67a
5 changed files with 63 additions and 0 deletions

View File

@ -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);

View File

@ -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"]
}
}
}

View File

@ -0,0 +1,2 @@
module EnumList
typeinfo enumlist.qmltypes

View File

@ -0,0 +1,8 @@
import EnumList
import QtQml
MyCustomType {
id: myType
requiredConditions: [Configuration.Condition.A, Configuration.Condition.C]
}

View File

@ -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");