diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-16 14:50:24 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-19 16:37:44 +0100 |
commit | f726d237277de0f4c8f276d20a5bb1b6a8cd007c (patch) | |
tree | b6e089eb68027297447bcd2cfd633830679855f5 /tools/qmllint | |
parent | 266dbbef1fdc34a9740458e86f0a0ee3fffa3f98 (diff) |
qmllint: Break inheritance cycles
Previously we would run into infinite loops on those. Mind that qmllint
will reject a file called Window.qml that imports QtQuick.Window and
then instantiates a Window {}. Such a thing is bad style.
Task-number: QTBUG-82817
Change-Id: I6db82ca1794c3020dcb7d7e837fe44f72bca5029
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint')
-rw-r--r-- | tools/qmllint/findunqualified.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp index 5bb9b62529..9bb9395015 100644 --- a/tools/qmllint/findunqualified.cpp +++ b/tools/qmllint/findunqualified.cpp @@ -367,11 +367,28 @@ void FindUnqualifiedIDVisitor::importFileOrDirectory(const QString &fileOrDirect void FindUnqualifiedIDVisitor::importExportedNames(const QStringRef &prefix, QString name) { + QList<ScopeTree::ConstPtr> scopes; for (;;) { ScopeTree::ConstPtr scope = m_exportedName2Scope.value(m_exportedName2Scope.contains(name) ? name : prefix + QLatin1Char('.') + name); if (scope) { + if (scopes.contains(scope)) { + QString inheritenceCycle = name; + for (const auto seen: qAsConst(scopes)) { + inheritenceCycle.append(QLatin1String(" -> ")); + inheritenceCycle.append(seen->superclassName()); + } + + m_colorOut.write(QLatin1String("Warning: "), Warning); + m_colorOut.write(QString::fromLatin1("%1 is part of an inheritance cycle: %2\n") + .arg(name) + .arg(inheritenceCycle)); + m_unknownImports.insert(name); + m_visitFailed = true; + break; + } + scopes.append(scope); const auto properties = scope->properties(); for (auto property : properties) { property.setType(m_exportedName2Scope.value(property.typeName()).get()); |