diff options
author | Evgeniy A. Dushistov <dushistov@mail.ru> | 2020-06-16 23:52:24 +0300 |
---|---|---|
committer | Evgeniy A. Dushistov <dushistov@mail.ru> | 2020-06-17 14:04:42 +0300 |
commit | 3615c72b666633cef9045012bbb05d5372c35cdf (patch) | |
tree | 8c6a456db529bd46e2bec9f6b23e0990c8e4fd2f | |
parent | 1b10ce6a08edbc2ac7e8fd7e97e3fc691f2081df (diff) |
qmllint: fix wrong warning about enum usage
Fixes: QTBUG-83796
Change-Id: I635bbfd98cf7be8418b454626ba7725e92b71c2c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | tests/auto/qml/qmllint/data/EnumAccess1.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/EnumAccess2.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 2 | ||||
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 6 | ||||
-rw-r--r-- | tools/qmllint/importedmembersvisitor.cpp | 12 | ||||
-rw-r--r-- | tools/qmllint/importedmembersvisitor.h | 1 |
6 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qml/qmllint/data/EnumAccess1.qml b/tests/auto/qml/qmllint/data/EnumAccess1.qml new file mode 100644 index 0000000000..8392930b65 --- /dev/null +++ b/tests/auto/qml/qmllint/data/EnumAccess1.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + enum Status { + On, Off + } + + property int status: EnumAccess1.Off +} diff --git a/tests/auto/qml/qmllint/data/EnumAccess2.qml b/tests/auto/qml/qmllint/data/EnumAccess2.qml new file mode 100644 index 0000000000..9aa6e1bac8 --- /dev/null +++ b/tests/auto/qml/qmllint/data/EnumAccess2.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + enum Status { + On, Off + } + + property int status: EnumAccess1.Status.Off +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index bdb5cf37c0..2c7998b571 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -220,6 +220,8 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("unknownBuiltinFont") << QStringLiteral("ButtonLoader.qml"); QTest::newRow("confusingImport") << QStringLiteral("Dialog.qml"); QTest::newRow("qualifiedAttached") << QStringLiteral("Drawer.qml"); + QTest::newRow("EnumAccess1") << QStringLiteral("EnumAccess1.qml"); + QTest::newRow("EnumAccess2") << QStringLiteral("EnumAccess2.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 32c2fa4d79..e1593182ab 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -173,6 +173,12 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> & const auto enums = scope->enums(); for (const auto &enumerator : enums) { + if (enumerator.name() == access.m_name) { + detectedRestrictiveKind = QLatin1String("enum"); + detectedRestrictiveName = access.m_name; + expectedNext.append(enumerator.keys()); + break; + } for (const QString &key : enumerator.keys()) { if (access.m_name == key) { detectedRestrictiveKind = QLatin1String("enum"); diff --git a/tools/qmllint/importedmembersvisitor.cpp b/tools/qmllint/importedmembersvisitor.cpp index bf3787d489..7bc58dee24 100644 --- a/tools/qmllint/importedmembersvisitor.cpp +++ b/tools/qmllint/importedmembersvisitor.cpp @@ -51,6 +51,9 @@ ScopeTree::Ptr ImportedMembersVisitor::result(const QString &scopeName) const for (const auto &method : m_rootObject->methods()) result->addMethod(method); + for (const auto &enumerator : m_rootObject->enums()) + result->addEnum(enumerator); + return result; } @@ -151,6 +154,15 @@ bool ImportedMembersVisitor::visit(UiScriptBinding *scriptBinding) return true; } +bool ImportedMembersVisitor::visit(QQmlJS::AST::UiEnumDeclaration *uied) +{ + MetaEnum qmlEnum(uied->name.toString()); + for (const auto *member = uied->members; member; member = member->next) + qmlEnum.addKey(member->member.toString()); + currentObject()->addEnum(qmlEnum); + return true; +} + void ImportedMembersVisitor::throwRecursionDepthError() { m_colorOut->write(QStringLiteral("Error"), Error); diff --git a/tools/qmllint/importedmembersvisitor.h b/tools/qmllint/importedmembersvisitor.h index 045ba00420..023e58df73 100644 --- a/tools/qmllint/importedmembersvisitor.h +++ b/tools/qmllint/importedmembersvisitor.h @@ -59,6 +59,7 @@ private: bool visit(QQmlJS::AST::UiPublicMember *) override; bool visit(QQmlJS::AST::UiSourceElement *) override; bool visit(QQmlJS::AST::UiScriptBinding *) override; + bool visit(QQmlJS::AST::UiEnumDeclaration *uied) override; void throwRecursionDepthError() override; ScopeTree::Ptr currentObject() const { return m_currentObjects.back(); } |