aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-05-20 14:09:08 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-05-26 14:46:39 +0200
commit0472a7a4326cf9ac1abdcbc0910c3b13f5c4fb5a (patch)
treea6d6ca7ecebcd733d11997f23a7ef2114b078457 /tools
parente2f247fafcd90c02e5db686c791ff4818be9cc50 (diff)
Evaluate type assertions in QML
Type assertions actually check whether the expression matches the type, and return null if it doesn't. [ChangeLog][QtQml] You can use TypeScript-like type assertions using "as" now. In contrast to TypeScript, QML's type assertions are enforced at runtime. If the type doesn't match, null is returned for object types. Also, type assertions can only cast to object types. There is no way to create a value type or primitive type reference. As value types and primitives cannot be polymorphic, this doesn't matter, though. There are other ways of converting those. Task-number: QTBUG-93662 Change-Id: I00fce3d4ea7a8c6b4631c580eaf6c113ac485813 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmllint/findwarnings.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp
index cde446c16e..bc228fa8e1 100644
--- a/tools/qmllint/findwarnings.cpp
+++ b/tools/qmllint/findwarnings.cpp
@@ -666,10 +666,12 @@ bool FindWarningVisitor::visit(QQmlJS::AST::BinaryExpression *)
void FindWarningVisitor::endVisit(QQmlJS::AST::BinaryExpression *binExp)
{
- if (binExp->op == QSOperator::As && m_fieldMemberBase == binExp->left)
+ if (binExp->op == QSOperator::As
+ && (m_fieldMemberBase == binExp->left || m_fieldMemberBase == binExp->right)) {
m_fieldMemberBase = binExp;
- else
+ } else {
m_fieldMemberBase = nullptr;
+ }
}
bool FindWarningVisitor::visit(QQmlJS::AST::UiPublicMember *uipb)