From 45d39a1685e72975dd9bd4d3e4a67aab59eeae48 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 6 Jun 2018 08:42:40 +0200 Subject: Fix array destructuring nested in a rest element Change-Id: I3a8c15fe221bff04a3b9b21ed8c0b06c04770a3d Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4codegen.cpp | 11 +++++------ src/qml/parser/qqmljsast.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index d71d36845b..b3b522e661 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -484,6 +484,7 @@ Codegen::Reference Codegen::targetForPatternElement(AST::PatternElement *p) void Codegen::initializeAndDestructureBindingElement(AST::PatternElement *e, const Reference &base) { + Q_ASSERT(e->type == AST::PatternElement::Binding || e->type == AST::PatternElement::RestElement); RegisterScope scope(this); Reference baseRef = (base.isAccumulator()) ? base.storeOnStack() : base; Reference varToStore = targetForPatternElement(e); @@ -619,12 +620,10 @@ void Codegen::destructureElementList(const Codegen::Reference &array, PatternEle bool last = !p->next || (!p->next->elision && !p->next->element); if (last) iteratorDone.storeConsumeAccumulator(); - if (e->type != PatternElement::RestElement) { - initializeAndDestructureBindingElement(e, iteratorValue); - if (hasError) { - end.link(); - return; - } + initializeAndDestructureBindingElement(e, iteratorValue); + if (hasError) { + end.link(); + return; } } } diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp index e9e33f7561..b338c5bbfe 100644 --- a/src/qml/parser/qqmljsast.cpp +++ b/src/qml/parser/qqmljsast.cpp @@ -399,28 +399,28 @@ bool PatternElement::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceL *errorMessage = QString::fromLatin1("Invalid lhs expression after '...' in destructuring expression."); return false; } - bindingTarget = lhs; - return true; - } - type = PatternElement::Binding; + } else { + type = PatternElement::Binding; - if (BinaryExpression *b = init->binaryExpressionCast()) { - if (b->op != QSOperator::Assign) { - *errorLocation = b->operatorToken; - *errorMessage = QString::fromLatin1("Invalid assignment operation in destructuring expression"); + if (BinaryExpression *b = init->binaryExpressionCast()) { + if (b->op != QSOperator::Assign) { + *errorLocation = b->operatorToken; + *errorMessage = QString::fromLatin1("Invalid assignment operation in destructuring expression"); + return false; + } + lhs = b->left->leftHandSideExpressionCast(); + initializer = b->right; + Q_ASSERT(lhs); + } else { + lhs = init->leftHandSideExpressionCast(); + } + if (!lhs) { + *errorLocation = init->firstSourceLocation(); + *errorMessage = QString::fromLatin1("Destructuring target is not a left hand side expression."); return false; } - lhs = b->left->leftHandSideExpressionCast(); - initializer = b->right; - Q_ASSERT(lhs); - } else { - lhs = init->leftHandSideExpressionCast(); - } - if (!lhs) { - *errorLocation = init->firstSourceLocation(); - *errorMessage = QString::fromLatin1("Destructuring target is not a left hand side expression."); - return false; } + if (auto *i = cast(lhs)) { bindingIdentifier = i->name.toString(); identifierToken = i->identifierToken; -- cgit v1.2.3