aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-11-25 16:02:35 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-11-29 16:13:19 +0100
commit97d307434445d82ed03cdb199d1d662853915065 (patch)
treead679a9094ff0d694701f287da4852a84e9e4621
parent40f073b1fa5584409a00825ba70ee6f88ff7ed43 (diff)
qmllint: Support opening the same grouped scope multiple times
Previously, we would only record the first source location for the scope, which produced errors and crashes on bindings to any further locations. We cannot properly test this on 6.2 because qmllint doesn't use the type propagator, yet. Fixes: QTBUG-96147 Change-Id: I02e6a551f1eafb31ac7c49d3250d74e5a3842971 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> (cherry picked from commit 6605839deb36862d9a480df51bd4243369356042)
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp2
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor_p.h10
-rw-r--r--tests/auto/qml/qmllint/data/multiGrouped.qml6
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
4 files changed, 18 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index 54dd5654c9..51561e748d 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -118,6 +118,7 @@ void QQmlJSImportVisitor::enterEnvironment(QQmlJSScope::ScopeType type, const QS
setScopeName(m_currentScope, type, name);
m_currentScope->setIsComposite(true);
m_currentScope->setSourceLocation(location);
+ m_scopesByIrLocation.insert({ location.startLine, location.startColumn }, m_currentScope);
}
bool QQmlJSImportVisitor::enterEnvironmentNonUnique(QQmlJSScope::ScopeType type,
@@ -142,6 +143,7 @@ bool QQmlJSImportVisitor::enterEnvironmentNonUnique(QQmlJSScope::ScopeType type,
return false;
}
// enter found scope
+ m_scopesByIrLocation.insert({ location.startLine, location.startColumn }, *it);
m_currentScope = *it;
return true;
}
diff --git a/src/qmlcompiler/qqmljsimportvisitor_p.h b/src/qmlcompiler/qqmljsimportvisitor_p.h
index cc1ccb3f3a..8908b60f76 100644
--- a/src/qmlcompiler/qqmljsimportvisitor_p.h
+++ b/src/qmlcompiler/qqmljsimportvisitor_p.h
@@ -46,7 +46,7 @@
#include <private/qqmljsast_p.h>
#include <private/qqmljsdiagnosticmessage_p.h>
#include <private/qqmljsimporter_p.h>
-
+#include <private/qv4compileddata_p.h>
QT_BEGIN_NAMESPACE
@@ -66,6 +66,10 @@ public:
QHash<QString, QQmlJSScope::ConstPtr> imports() const { return m_rootScopeImports; }
QHash<QString, QQmlJSScope::ConstPtr> addressableScopes() const { return m_scopesById; }
+ QHash<QV4::CompiledData::Location, QQmlJSScope::ConstPtr> scopesBylocation() const
+ {
+ return m_scopesByIrLocation;
+ }
static QString implicitImportDirectory(
const QString &localFile, QQmlJSResourceFileMapper *mapper);
@@ -145,6 +149,10 @@ protected:
QHash<QString, QQmlJSScope::ConstPtr> m_scopesById;
QHash<QString, QQmlJSScope::ConstPtr> m_rootScopeImports;
+ // We need to record the locations as IR locations because those contain less data.
+ // This way we can look up objects by IR location later.
+ QHash<QV4::CompiledData::Location, QQmlJSScope::ConstPtr> m_scopesByIrLocation;
+
// Maps all qmlNames to the source location of their import
QMultiHash<QString, QQmlJS::SourceLocation> m_importTypeLocationMap;
// Contains all import source locations (could be extracted from above but that is expensive)
diff --git a/tests/auto/qml/qmllint/data/multiGrouped.qml b/tests/auto/qml/qmllint/data/multiGrouped.qml
new file mode 100644
index 0000000000..ab6bd5bd02
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/multiGrouped.qml
@@ -0,0 +1,6 @@
+import QtQuick
+
+Item {
+ anchors.verticalCenter: parent.verticalCenter
+ anchors { right: parent.left }
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 09e2683236..2a441086ad 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -810,6 +810,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("required property in Component") << QStringLiteral("requiredPropertyInComponent.qml");
QTest::newRow("connectionNoParent") << QStringLiteral("connectionNoParent.qml"); // QTBUG-97600
QTest::newRow("on binding in grouped property") << QStringLiteral("onBindingInGroupedProperty.qml");
+ QTest::newRow("multipleGrouped") << QStringLiteral("multiGrouped.qml");
}
void TestQmllint::cleanQmlCode()