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 | |
| parent | 5715732755b9bd36d5b6d14c5294e693c4d09ca8 (diff) | |
Fix sanity checks when declaring variables
Change-Id: Ib2968d4da22eab06b8a82eb7697d5e9fce6dc43d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
| -rw-r--r-- | src/qml/compiler/qv4compilercontext.cpp | 12 | ||||
| -rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 9 |
2 files changed, 8 insertions, 13 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; diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 40459b3b28..47329e978b 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -209,15 +209,8 @@ bool ScanFunctions::visit(PatternElement *ast) _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Missing initializer in const declaration")); return false; } - const Context::Member *m = nullptr; - if (_context->memberInfo(name, &m)) { - if (m->isLexicallyScoped() || ast->isLexicallyScoped()) { - _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Identifier %1 has already been declared").arg(name)); - return false; - } - } if (!_context->addLocalVar(name, ast->initializer ? Context::VariableDefinition : Context::VariableDeclaration, ast->scope)) { - _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Identifier %1 has already been declared").arg(ast->bindingIdentifier)); + _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Identifier %1 has already been declared").arg(name)); return false; } } |
