aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-01-26 11:14:13 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-01-26 13:19:38 +0100
commited59dfeb706242d314aa21889ad0f5a7e028069f (patch)
treee3eae93b16692733caa34969328c2016b3c74257 /tools
parent48b6e192bbb023bb19c9de81c1e3d3ac3bca238c (diff)
qmllint: Complain if member access check fails for namespaced types
Before, we would prepend the namespace to the name, but then continue right away, never checking the new name. Change-Id: If90db7d33536fb4b549321c2d6b677040605b6f0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmllint/checkidentifiers.cpp47
1 files changed, 34 insertions, 13 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 0517f67ed5..32a47891d5 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -299,7 +299,7 @@ bool CheckIdentifiers::operator()(
if (memberAccessChain.isEmpty())
continue;
- const auto memberAccessBase = memberAccessChain.takeFirst();
+ auto memberAccessBase = memberAccessChain.takeFirst();
const auto jsId = currentScope->findJSIdentifier(memberAccessBase.m_name);
if (jsId.has_value() && jsId->kind != QQmlJSScope::JavaScriptIdentifier::Injected)
continue;
@@ -354,24 +354,45 @@ bool CheckIdentifiers::operator()(
continue;
}
- const auto typeIt = m_types.find(memberAccessBase.m_name);
- if (typeIt != m_types.end()) {
- if (typeIt->isNull()) {
- // This is a namespaced import. Check with the full name.
- if (!memberAccessChain.isEmpty())
- memberAccessChain.front().m_name.prepend(memberAccessBase.m_name + u'.');
- } else if (!checkMemberAccess(memberAccessChain, *typeIt)) {
- noUnqualifiedIdentifier = false;
+ const QString baseName = memberAccessBase.m_name;
+ auto typeIt = m_types.find(memberAccessBase.m_name);
+ bool baseIsPrefixed = false;
+ while (typeIt != m_types.end() && typeIt->isNull()) {
+ // This is a namespaced import. Check with the full name.
+ if (!memberAccessChain.isEmpty()) {
+ auto location = memberAccessBase.m_location;
+ memberAccessBase = memberAccessChain.takeFirst();
+ memberAccessBase.m_name.prepend(baseName + u'.');
+ location.length = memberAccessBase.m_location.offset - location.offset
+ + memberAccessBase.m_location.length;
+ memberAccessBase.m_location = location;
+ typeIt = m_types.find(memberAccessBase.m_name);
+ baseIsPrefixed = true;
}
+ }
+
+ if (typeIt != m_types.end() && !typeIt->isNull()) {
+ if (!checkMemberAccess(memberAccessChain, *typeIt))
+ noUnqualifiedIdentifier = false;
continue;
}
noUnqualifiedIdentifier = false;
const auto location = memberAccessBase.m_location;
- m_colorOut->writePrefixedMessage(QString::fromLatin1("unqualified access at %1:%2:%3\n")
- .arg(m_fileName)
- .arg(location.startLine).arg(location.startColumn),
- Warning);
+
+ if (baseIsPrefixed) {
+ m_colorOut->writePrefixedMessage(
+ QString::fromLatin1("type not found in namespace at %1:%2:%3\n")
+ .arg(m_fileName)
+ .arg(location.startLine).arg(location.startColumn),
+ Warning);
+ } else {
+ m_colorOut->writePrefixedMessage(
+ QString::fromLatin1("unqualified access at %1:%2:%3\n")
+ .arg(m_fileName)
+ .arg(location.startLine).arg(location.startColumn),
+ Warning);
+ }
printContext(m_code, m_colorOut, location);