diff options
-rw-r--r-- | tests/auto/qml/qmllint/data/badParent.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/goodParent.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/parentIsComponent.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 9 | ||||
-rw-r--r-- | tools/qmllint/findunqualified.cpp | 2 | ||||
-rw-r--r-- | tools/qmllint/scopetree.cpp | 9 | ||||
-rw-r--r-- | tools/qmllint/scopetree.h | 1 |
7 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qml/qmllint/data/badParent.qml b/tests/auto/qml/qmllint/data/badParent.qml new file mode 100644 index 0000000000..f381f059cc --- /dev/null +++ b/tests/auto/qml/qmllint/data/badParent.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +Item { + Item { + property int yyy: parent.rrr + } +} diff --git a/tests/auto/qml/qmllint/data/goodParent.qml b/tests/auto/qml/qmllint/data/goodParent.qml new file mode 100644 index 0000000000..413337713a --- /dev/null +++ b/tests/auto/qml/qmllint/data/goodParent.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +Item { + property int rrr: 5 + Item { + property int yyy: parent.rrr + } +} diff --git a/tests/auto/qml/qmllint/data/parentIsComponent.qml b/tests/auto/qml/qmllint/data/parentIsComponent.qml new file mode 100644 index 0000000000..a74bf9e4e8 --- /dev/null +++ b/tests/auto/qml/qmllint/data/parentIsComponent.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + Component { + id: foo + Item { + property real yyy: parent.progress + Component.onCompleted: console.log(yyy) + } + } + + property var stuff: foo.createObject() +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 5066451f6d..f906c3ac45 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -148,6 +148,14 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("badAliasProperty.qml") << QString("Warning: Property \"nowhere\" not found on type \"QtObject\" at 5:32") << QString(); + QTest::newRow("badParent") + << QStringLiteral("badParent.qml") + << QString("Warning: Property \"rrr\" not found on type \"Item\" at 5:34") + << QString(); + QTest::newRow("parentIsComponent") + << QStringLiteral("parentIsComponent.qml") + << QString("Warning: Property \"progress\" not found on type \"QQuickItem\" at 7:39") + << QString(); } void TestQmllint::dirtyQmlCode() @@ -177,6 +185,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("esmodule") << QStringLiteral("esmodule.mjs"); QTest::newRow("methodsInJavascript") << QStringLiteral("javascriptMethods.qml"); QTest::newRow("goodAlias") << QStringLiteral("goodAlias.qml"); + QTest::newRow("goodParent") << QStringLiteral("goodParent.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp index 359510f5f7..d0dc3a3711 100644 --- a/tools/qmllint/findunqualified.cpp +++ b/tools/qmllint/findunqualified.cpp @@ -888,7 +888,9 @@ bool FindUnqualifiedIDVisitor::visit(QQmlJS::AST::PatternElement *element) void FindUnqualifiedIDVisitor::endVisit(QQmlJS::AST::UiObjectDefinition *) { + auto childScope = m_currentScope; leaveEnvironment(); + childScope->updateParentProperty(m_currentScope); } bool FindUnqualifiedIDVisitor::visit(QQmlJS::AST::FieldMemberExpression *) diff --git a/tools/qmllint/scopetree.cpp b/tools/qmllint/scopetree.cpp index cac064eb27..e5b0eecc5f 100644 --- a/tools/qmllint/scopetree.cpp +++ b/tools/qmllint/scopetree.cpp @@ -448,6 +448,15 @@ void ScopeTree::setExportMetaObjectRevision(int exportIndex, int metaObjectRevis m_exports[exportIndex].setMetaObjectRevision(metaObjectRevision); } +void ScopeTree::updateParentProperty(const ScopeTree *scope) +{ + auto it = m_properties.find(QLatin1String("parent")); + if (it != m_properties.end() + && scope->name() != QLatin1String("Component") + && scope->name() != 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/qmllint/scopetree.h b/tools/qmllint/scopetree.h index 00cb466eb9..eb5f384477 100644 --- a/tools/qmllint/scopetree.h +++ b/tools/qmllint/scopetree.h @@ -153,6 +153,7 @@ public: void addProperty(const MetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); } QHash<QString, MetaProperty> properties() const { return m_properties; } + void updateParentProperty(const ScopeTree *scope); QString defaultPropertyName() const { return m_defaultPropertyName; } void setDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; } |