diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-10 22:55:55 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-11 07:17:29 +0000 |
commit | fd183d3db9d1eba4f7dd3e978192a247bf7dba85 (patch) | |
tree | c8359248c07cb4467e4c8b844a07a0d4ba8abaab /src/qml | |
parent | e203a868470ab2e435111127f00530f4d8cc581d (diff) |
Give for loops a proper block scope for it's lexically declared vars
Change-Id: I71c40d1d061ac3c1c623dbbf8f7967c9ec35c082
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 2 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 7 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions_p.h | 1 |
3 files changed, 10 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index fc7ca911e8..687731c32b 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2687,6 +2687,8 @@ bool Codegen::visit(ForStatement *ast) RegisterScope scope(this); + ControlFlowBlock controlFlow(this, ast); + if (ast->initialiser) statement(ast->initialiser); else if (ast->declarations) diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 31663e2162..c2256537c4 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -320,6 +320,8 @@ bool ScanFunctions::visit(DoWhileStatement *ast) { } bool ScanFunctions::visit(ForStatement *ast) { + enterEnvironment(ast, ContextType::Block); + _context->name = QLatin1String("For"); Node::accept(ast->initialiser, this); Node::accept(ast->declarations, this); Node::accept(ast->condition, this); @@ -331,6 +333,11 @@ bool ScanFunctions::visit(ForStatement *ast) { return false; } +void ScanFunctions::endVisit(ForStatement *) +{ + leaveEnvironment(); +} + bool ScanFunctions::visit(ForEachStatement *ast) { enterEnvironment(ast, ContextType::Block); _context->name = QLatin1String("Foreach"); diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h index 4d52548637..b9b41781c4 100644 --- a/src/qml/compiler/qv4compilerscanfunctions_p.h +++ b/src/qml/compiler/qv4compilerscanfunctions_p.h @@ -125,6 +125,7 @@ protected: bool visit(AST::DoWhileStatement *ast) override; bool visit(AST::ForStatement *ast) override; + void endVisit(AST::ForStatement *) override; bool visit(AST::ForEachStatement *ast) override; void endVisit(AST::ForEachStatement *) override; |