From 1b5a6c19ab701c9b94b1ffb094999c34643bcd1d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 16 Mar 2020 15:07:04 +0100 Subject: qmllint: Don't crash on IDs that aren't scopes In particular, those can be qualifiers for imports, in which case we have to combine them with the next segment in order to find the type. Task-number: QTBUG-82817 Change-Id: I217a79572cd1e160dcbbcb9541c53941c81ab76c Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmllint/data/Drawer.qml | 5 +++++ tests/auto/qml/qmllint/tst_qmllint.cpp | 1 + tools/qmllint/scopetree.cpp | 21 ++++++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/auto/qml/qmllint/data/Drawer.qml diff --git a/tests/auto/qml/qmllint/data/Drawer.qml b/tests/auto/qml/qmllint/data/Drawer.qml new file mode 100644 index 0000000000..db1d785c6c --- /dev/null +++ b/tests/auto/qml/qmllint/data/Drawer.qml @@ -0,0 +1,5 @@ +import QtQml 2.12 as T + +T.QtObject { + objectName: T.Component.objectName +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 3e5237aebe..ed401d59e0 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -194,6 +194,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("AttachedProps") << QStringLiteral("AttachedProps.qml"); QTest::newRow("unknownBuiltinFont") << QStringLiteral("ButtonLoader.qml"); QTest::newRow("confusingImport") << QStringLiteral("Dialog.qml"); + QTest::newRow("qualifiedAttached") << QStringLiteral("Drawer.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/scopetree.cpp b/tools/qmllint/scopetree.cpp index 5c0fa526a4..07413094c0 100644 --- a/tools/qmllint/scopetree.cpp +++ b/tools/qmllint/scopetree.cpp @@ -293,9 +293,24 @@ bool ScopeTree::recheckIdentifiers( auto it = qmlIDs.find(memberAccessTree->m_name); if (it != qmlIDs.end()) { - if (!checkMemberAccess(code, memberAccessTree.get(), *it, types, colorOut)) - noUnqualifiedIdentifier = false; - continue; + if (*it != nullptr) { + if (!checkMemberAccess(code, memberAccessTree.get(), *it, types, colorOut)) + noUnqualifiedIdentifier = false; + continue; + } else if (memberAccessTree->m_child + && memberAccessTree->m_child->m_name.front().isUpper()) { + // It could be a qualified type name + const QString qualified = memberAccessTree->m_name + QLatin1Char('.') + + memberAccessTree->m_child->m_name; + const auto typeIt = types.find(qualified); + if (typeIt != types.end()) { + if (!checkMemberAccess(code, memberAccessTree->m_child.get(), typeIt->get(), + types, colorOut)) { + noUnqualifiedIdentifier = false; + } + continue; + } + } } auto qmlScope = currentScope->currentQMLScope(); -- cgit v1.2.3