diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-04-13 23:13:02 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-02 14:19:05 +0000 |
commit | 10b127b620f983478e656188bbcf7246afb7cb39 (patch) | |
tree | e8b5a3f9472da38d22cfed43797414b7cf9af953 /src/qml/compiler/qv4compilercontext.cpp | |
parent | 5715732755b9bd36d5b6d14c5294e693c4d09ca8 (diff) |
Fix sanity checks when declaring variables
Change-Id: Ib2968d4da22eab06b8a82eb7697d5e9fce6dc43d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilercontext.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilercontext.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp index d232a43291..7dc8b68d78 100644 --- a/src/qml/compiler/qv4compilercontext.cpp +++ b/src/qml/compiler/qv4compilercontext.cpp @@ -73,16 +73,13 @@ Context *Module::newContext(Node *node, Context *parent, ContextType contextType bool Context::addLocalVar(const QString &name, Context::MemberType type, VariableScope scope, FunctionExpression *function) { - // hoist var declarations to the function level - if (contextType == ContextType::Block && (scope == VariableScope::Var && type != MemberType::FunctionDefinition)) - return parent->addLocalVar(name, type, scope, function); - + // ### can this happen? if (name.isEmpty()) return true; if (type != FunctionDefinition) { if (formals && formals->containsName(name)) - return (scope == QQmlJS::AST::VariableScope::Var); + return (scope == VariableScope::Var); } if (!isCatchBlock || name != catchedVariable) { MemberMap::iterator it = members.find(name); @@ -96,6 +93,11 @@ bool Context::addLocalVar(const QString &name, Context::MemberType type, Variabl return true; } } + + // hoist var declarations to the function level + if (contextType == ContextType::Block && (scope == VariableScope::Var && type != MemberType::FunctionDefinition)) + return parent->addLocalVar(name, type, scope, function); + Member m; m.type = type; m.function = function; |