aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljs.g
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 /src/qml/parser/qqmljs.g
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 'src/qml/parser/qqmljs.g')
-rw-r--r--src/qml/parser/qqmljs.g24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index 2716983f42..eb082b77c2 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -1730,14 +1730,6 @@ TypeAnnotation: T_COLON Type;
} break;
./
-
-TypeExpression: Type;
-/.
- case $rule_number: {
- sym(1).Expression = new (pool) AST::TypeExpression(sym(1).Type);
- } break;
-./
-
TypeAnnotationOpt: TypeAnnotation;
TypeAnnotationOpt: ;
/.
@@ -2763,30 +2755,22 @@ RelationalOperator: T_INSTANCEOF;
sym(1).ival = QSOperator::InstanceOf;
} break;
./
-
-RelationalExpression_In: RelationalExpression_In T_IN ShiftExpression;
+RelationalOperator: T_AS;
/.
case $rule_number: {
- AST::BinaryExpression *node = new (pool) AST::BinaryExpression(sym(1).Expression, QSOperator::In, sym(3).Expression);
- node->operatorToken = loc(2);
- sym(1).Node = node;
+ sym(1).ival = QSOperator::As;
} break;
./
-TypeAssertExpression_In: RelationalExpression_In T_AS TypeExpression;
-/. case $rule_number: Q_FALLTHROUGH(); ./
-TypeAssertExpression: RelationalExpression T_AS TypeExpression;
+RelationalExpression_In: RelationalExpression_In T_IN ShiftExpression;
/.
case $rule_number: {
- AST::BinaryExpression *node = new (pool) AST::BinaryExpression(sym(1).Expression, QSOperator::As, sym(3).Expression);
+ AST::BinaryExpression *node = new (pool) AST::BinaryExpression(sym(1).Expression, QSOperator::In, sym(3).Expression);
node->operatorToken = loc(2);
sym(1).Node = node;
} break;
./
-RelationalExpression_In: TypeAssertExpression_In;
-RelationalExpression: TypeAssertExpression;
-
EqualityExpression_In: RelationalExpression_In;
EqualityExpression: RelationalExpression;