aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-06-23 16:06:58 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-06-26 10:18:22 +0000
commit6d8aca544ccb1e2624a679e2d65622461f643291 (patch)
tree67f48176a84670594ef359ce02b4ef129bf3187b
parentd4feac29e3a3f6f3c9eb320553cd926fef1c536e (diff)
qmllint: Resolve enums from parent types
Fixes: QTBUG-85185 Fixes: QTBUG-84036 Change-Id: If0989a85df93903fee6cb146a515cd362160ff49 Reviewed-by: Evgeniy Dushistov <dushistov@mail.ru> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--tests/auto/qml/qmllint/data/parentEnum.qml7
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
-rw-r--r--tools/qmllint/checkidentifiers.cpp35
3 files changed, 28 insertions, 15 deletions
diff --git a/tests/auto/qml/qmllint/data/parentEnum.qml b/tests/auto/qml/qmllint/data/parentEnum.qml
new file mode 100644
index 0000000000..313760f59a
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/parentEnum.qml
@@ -0,0 +1,7 @@
+import QtQuick
+
+Item {
+ width: 640
+ height: 480
+ property int t: PointerDevice.Position
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 6d472842ca..7466043389 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -229,6 +229,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("ListProperty") << QStringLiteral("ListProperty.qml");
QTest::newRow("AttachedType") << QStringLiteral("AttachedType.qml");
QTest::newRow("qmldirImportAndDepend") << QStringLiteral("qmldirImportAndDepend/good.qml");
+ QTest::newRow("ParentEnum") << QStringLiteral("parentEnum.qml");
}
void TestQmllint::cleanQmlCode()
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 2771e1cfb2..09678c2e6a 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -203,24 +203,28 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
if (scopeMethodIt != methods.end())
return true; // Access to property of JS function
- 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) {
+ auto checkEnums = [&](const ScopeTree::ConstPtr &scope) {
+ const auto enums = scope->enums();
+ for (const auto &enumerator : enums) {
+ if (enumerator.name() == access.m_name) {
detectedRestrictiveKind = QLatin1String("enum");
detectedRestrictiveName = access.m_name;
- break;
+ expectedNext.append(enumerator.keys());
+ return true;
+ }
+ for (const QString &key : enumerator.keys()) {
+ if (access.m_name == key) {
+ detectedRestrictiveKind = QLatin1String("enum");
+ detectedRestrictiveName = access.m_name;
+ return true;
+ }
}
}
- if (!detectedRestrictiveName.isEmpty())
- break;
- }
+ return false;
+ };
+
+ checkEnums(scope);
+
if (!detectedRestrictiveName.isEmpty())
continue;
@@ -243,7 +247,8 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
detectedRestrictiveKind = QLatin1String("method");
return true;
}
- return false;
+
+ return checkEnums(type);
});
if (typeFound)
continue;