aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/compiler/qv4codegen.cpp16
-rw-r--r--src/qml/compiler/qv4codegen_p.h3
-rw-r--r--src/qml/compiler/qv4compilercontext.cpp1
-rw-r--r--src/qml/compiler/qv4compilercontext_p.h1
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp3
5 files changed, 21 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index b57a21eab6..af63c7edf7 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -51,6 +51,13 @@ void CodegenWarningInterface::reportVarUsedBeforeDeclaration(
<< declarationLocation.startLine << ":" << declarationLocation.startColumn << ".";
}
+void CodegenWarningInterface::reportFunctionUsedBeforeDeclaration(const QString &, const QString &,
+ QQmlJS::SourceLocation,
+ QQmlJS::SourceLocation)
+{
+ // we don't report this by default, only when using qmllint.
+}
+
static inline void setJumpOutLocation(QV4::Moth::BytecodeGenerator *bytecodeGenerator,
const Statement *body, const SourceLocation &fallback)
{
@@ -2680,8 +2687,13 @@ Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs, co
if (resolved.declarationLocation.isValid() && accessLocation.isValid()
&& resolved.declarationLocation.begin() > accessLocation.end()) {
Q_ASSERT(_interface);
- _interface->reportVarUsedBeforeDeclaration(
- name, url().toLocalFile(), resolved.declarationLocation, accessLocation);
+ if (resolved.memberType == Context::FunctionDefinition) {
+ _interface->reportFunctionUsedBeforeDeclaration(
+ name, url().toLocalFile(), resolved.declarationLocation, accessLocation);
+ } else {
+ _interface->reportVarUsedBeforeDeclaration(
+ name, url().toLocalFile(), resolved.declarationLocation, accessLocation);
+ }
if (resolved.type == Context::ResolvedName::Stack && resolved.requiresTDZCheck)
throwsReferenceError = true;
}
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index 55c198d52c..20fea8990d 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -53,6 +53,9 @@ public:
virtual void reportVarUsedBeforeDeclaration(const QString &name, const QString &fileName,
QQmlJS::SourceLocation declarationLocation,
QQmlJS::SourceLocation accessLocation);
+ virtual void reportFunctionUsedBeforeDeclaration(const QString &name, const QString &fileName,
+ QQmlJS::SourceLocation declarationLocation,
+ QQmlJS::SourceLocation accessLocation);
virtual ~CodegenWarningInterface() = default;
};
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp
index 8c6526a9fa..84bf4877f9 100644
--- a/src/qml/compiler/qv4compilercontext.cpp
+++ b/src/qml/compiler/qv4compilercontext.cpp
@@ -108,6 +108,7 @@ Context::ResolvedName Context::resolveName(const QString &name, const QQmlJS::So
if (m.type != Context::UndefinedMember) {
result.type = m.canEscape ? ResolvedName::Local : ResolvedName::Stack;
+ result.memberType = m.type;
result.scope = scope;
result.index = m.index;
result.isConst = (m.scope == VariableScope::Const);
diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h
index c4087e771a..fc50fba997 100644
--- a/src/qml/compiler/qv4compilercontext_p.h
+++ b/src/qml/compiler/qv4compilercontext_p.h
@@ -337,6 +337,7 @@ struct Context {
Import
};
Type type = Unresolved;
+ Context::MemberType memberType = UndefinedMember;
bool isArgOrEval = false;
bool isConst = false;
bool requiresTDZCheck = false;
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp
index e520ccc002..c7e8b50e2b 100644
--- a/src/qml/compiler/qv4compilerscanfunctions.cpp
+++ b/src/qml/compiler/qv4compilerscanfunctions.cpp
@@ -655,7 +655,8 @@ bool ScanFunctions::enterFunction(
outerContext->hasNestedFunctions = true;
// The identifier of a function expression cannot be referenced from the enclosing environment.
if (nameContext == FunctionNameContext::Outer) {
- if (!outerContext->addLocalVar(name, Context::FunctionDefinition, VariableScope::Var, expr)) {
+ if (!outerContext->addLocalVar(name, Context::FunctionDefinition, VariableScope::Var,
+ expr, expr->identifierToken)) {
_cg->throwSyntaxError(ast->firstSourceLocation(), QStringLiteral("Identifier %1 has already been declared").arg(name));
return false;
}