diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-02 11:17:29 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-02 15:31:59 +0200 |
commit | febb6ba891616b71476b736d4c583054685c7766 (patch) | |
tree | 4a9be0ab41fcb3f844d6460497da2448f78fd9b3 | |
parent | b1afde8ada7959b29acb4ac0fae87d7a8ae8aa08 (diff) |
qmllint: Fix updating of parent property
We need to check for the baseTypeName, not for the internalName. Also,
this is not really the scope's business but a property of how qmllint
sets up its scopes.
Task-number: QTBUG-87116
Change-Id: I8f0e558a4a5861164c6e85f90e3d88e469ea0769
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Evgeniy Dushistov <dushistov@mail.ru>
-rw-r--r-- | tests/auto/qml/qmllint/data/anchors2.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/nanchors2.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 6 | ||||
-rw-r--r-- | tools/qmllint/findwarnings.cpp | 14 | ||||
-rw-r--r-- | tools/shared/scopetree.cpp | 9 | ||||
-rw-r--r-- | tools/shared/scopetree.h | 1 |
6 files changed, 31 insertions, 11 deletions
diff --git a/tests/auto/qml/qmllint/data/anchors2.qml b/tests/auto/qml/qmllint/data/anchors2.qml new file mode 100644 index 0000000000..8918cf01d4 --- /dev/null +++ b/tests/auto/qml/qmllint/data/anchors2.qml @@ -0,0 +1,6 @@ +import QtQuick 2.15 + +Rectangle { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter +} diff --git a/tests/auto/qml/qmllint/data/nanchors2.qml b/tests/auto/qml/qmllint/data/nanchors2.qml new file mode 100644 index 0000000000..99ac9e7dff --- /dev/null +++ b/tests/auto/qml/qmllint/data/nanchors2.qml @@ -0,0 +1,6 @@ +import QtQuick 2.15 + +Rectangle { + nanchors.horizontalCenter: parent.horizontalCenter + nanchors.verticalCenter: parent.verticalCenter +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index cd0042d291..da210e6abf 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -203,6 +203,10 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("nanchors1.qml") << QString() << QString(); + QTest::newRow("nanchors2") + << QStringLiteral("nanchors2.qml") + << QString() + << QString(); QTest::newRow("nanchors3") << QStringLiteral("nanchors3.qml") << QString() @@ -221,6 +225,7 @@ void TestQmllint::dirtyQmlCode() QVERIFY(process.waitForFinished()); QCOMPARE(process.exitStatus(), QProcess::NormalExit); QEXPECT_FAIL("nanchors1", "Invalid grouped properties are not detected", Abort); + QEXPECT_FAIL("nanchors2", "Invalid grouped properties are not detected", Abort); QEXPECT_FAIL("nanchors3", "Invalid grouped properties are not detected", Abort); QVERIFY(process.exitCode() != 0); }); @@ -262,6 +267,7 @@ void TestQmllint::cleanQmlCode_data() << QStringLiteral("javascriptMethodsInModuleGood.qml"); QTest::newRow("enumFromQtQml") << QStringLiteral("enumFromQtQml.qml"); QTest::newRow("anchors1") << QStringLiteral("anchors1.qml"); + QTest::newRow("anchors2") << QStringLiteral("anchors2.qml"); QTest::newRow("anchors3") << QStringLiteral("anchors3.qml"); } diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index fb69756415..09ef63d4bd 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -902,7 +902,19 @@ void FindWarningVisitor::endVisit(QQmlJS::AST::UiObjectDefinition *) { auto childScope = m_currentScope; leaveEnvironment(); - childScope->updateParentProperty(m_currentScope); + + if (m_currentScope->baseTypeName() == QStringLiteral("Component") + || m_currentScope->baseTypeName() == QStringLiteral("program")) { + return; + } + + const auto properties = childScope->properties(); + const auto it = properties.find(QStringLiteral("parent")); + if (it != properties.end()) { + auto property = *it; + property.setType(m_currentScope); + childScope->addProperty(property); + } } bool FindWarningVisitor::visit(QQmlJS::AST::FieldMemberExpression *) diff --git a/tools/shared/scopetree.cpp b/tools/shared/scopetree.cpp index 2ae2dfe054..0ead08aa10 100644 --- a/tools/shared/scopetree.cpp +++ b/tools/shared/scopetree.cpp @@ -190,15 +190,6 @@ void ScopeTree::setExportMetaObjectRevision(int exportIndex, int metaObjectRevis m_exports[exportIndex].setMetaObjectRevision(metaObjectRevision); } -void ScopeTree::updateParentProperty(const ScopeTree::ConstPtr &scope) -{ - auto it = m_properties.find(QLatin1String("parent")); - if (it != m_properties.end() - && scope->baseTypeName() != QLatin1String("Component") - && scope->internalName() != QLatin1String("program")) - it->setType(scope); -} - ScopeTree::Export::Export(QString package, QString type, const ComponentVersion &version, int metaObjectRevision) : m_package(std::move(package)), diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h index ecb9646db2..b4c241d561 100644 --- a/tools/shared/scopetree.h +++ b/tools/shared/scopetree.h @@ -159,7 +159,6 @@ public: void addProperty(const MetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); } QHash<QString, MetaProperty> properties() const { return m_properties; } - void updateParentProperty(const ScopeTree::ConstPtr &scope); QString defaultPropertyName() const { return m_defaultPropertyName; } void setDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; } |