aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-05-18 16:47:34 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-05-20 16:19:27 +0200
commit36ac9ab322d00ad8a2139bcf463275e3121bfb1f (patch)
tree6e1753cc82efefb97a7c630f10202988207c2df3
parent50841f233a78b970830e70452e62e8940ef8f061 (diff)
qmllint: Fix evaluation of type assertions
Previously, type assertions were ignored. The test case didn't fail because simple type casts were automatically detected when the derived objects were instantiated and assigned to base type properties. Pick-to: 5.15 Change-Id: I437e77ff38b7d570451cf27ca84e9897b519413f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--tests/auto/qml/qmllint/data/goodTypeAssertion.qml5
-rw-r--r--tools/qmllint/checkidentifiers.cpp6
-rw-r--r--tools/qmllint/findwarnings.cpp4
3 files changed, 8 insertions, 7 deletions
diff --git a/tests/auto/qml/qmllint/data/goodTypeAssertion.qml b/tests/auto/qml/qmllint/data/goodTypeAssertion.qml
index 6f5f52eb6b..85aaf50d06 100644
--- a/tests/auto/qml/qmllint/data/goodTypeAssertion.qml
+++ b/tests/auto/qml/qmllint/data/goodTypeAssertion.qml
@@ -1,6 +1,9 @@
import QtQuick 2.0
Item {
- property QtObject foo: Item { x: 4 }
+ id: root
+ function self() { return root }
+
+ property QtObject foo: self()
property real foox: (foo as Item).x
}
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index a9bc58661e..619fe8e4b9 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -186,15 +186,13 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
if (!detectedRestrictiveName.isEmpty())
continue;
- auto type = m_types.value(scopeName);
+ auto type = m_types.value(access.m_parentType.isEmpty() ? scopeName : access.m_parentType);
bool typeFound = false;
while (type) {
const auto typeProperties = type->properties();
const auto typeIt = typeProperties.find(access.m_name);
if (typeIt != typeProperties.end()) {
- const ScopeTree::ConstPtr propType = access.m_parentType.isEmpty()
- ? typeIt->type()
- : m_types.value(access.m_parentType);
+ const ScopeTree::ConstPtr propType = typeIt->type();
scope = propType ? propType : m_types.value(typeIt->typeName());
typeFound = true;
break;
diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp
index cecbf838d7..b177c5f5c4 100644
--- a/tools/qmllint/findwarnings.cpp
+++ b/tools/qmllint/findwarnings.cpp
@@ -977,8 +977,8 @@ void FindWarningVisitor::endVisit(QQmlJS::AST::FieldMemberExpression *fieldMembe
QString type;
if (auto *binary = cast<BinaryExpression *>(base)) {
if (binary->op == QSOperator::As) {
- if (auto *right = cast<IdentifierExpression *>(binary->right))
- type = right->name.toString();
+ if (auto *right = cast<TypeExpression *>(binary->right))
+ type = right->m_type->toString();
}
}
m_currentScope->accessMember(fieldMember->name.toString(),