From 0472a7a4326cf9ac1abdcbc0910c3b13f5c4fb5a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 20 May 2021 14:09:08 +0200 Subject: 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 Reviewed-by: Paul Wicking --- tools/qmllint/findwarnings.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tools') 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) -- cgit v1.2.3