diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-11 13:17:29 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-11 17:37:53 +0100 |
commit | ab71cdafca87513a4e214d3af056d8990bc1eddb (patch) | |
tree | 22ec625d15eba58c018e748fee55c25a231da709 /src/qml/compiler/qv4compilercontext_p.h | |
parent | 80bc943025398d0cdb29e4edbe096d8ac127263e (diff) |
QML: Warn about variables being used before their declaration
This collides with injected signal parameters. qmlcachegen cannot tell
those cases apart.
[ChangeLog][QML][Important Behavior Changes] QML warns about JavaScript
variables being used before their declaration now. This is almost always
a mistake. It is particularly dangerous in the presence of injected
signal parameters because qmlcachegen cannot identify a name collision
between an injected signal parameter and a variable being used before
its declaration. It therefore miscompiles such code. You can turn off
the deprecation warning using the "qt.qml.compiler" logging category.
Pick-to: 6.1
Task-number: QTBUG-89943
Change-Id: I8a9424ca8c6edd562402fe5c560ba7e8344b5585
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilercontext_p.h')
-rw-r--r-- | src/qml/compiler/qv4compilercontext_p.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h index 4a14009c35..da9d637c5f 100644 --- a/src/qml/compiler/qv4compilercontext_p.h +++ b/src/qml/compiler/qv4compilercontext_p.h @@ -183,7 +183,7 @@ struct Context { QQmlJS::AST::VariableScope scope = QQmlJS::AST::VariableScope::Var; mutable bool canEscape = false; QQmlJS::AST::FunctionExpression *function = nullptr; - QQmlJS::SourceLocation endOfInitializerLocation; + QQmlJS::SourceLocation declarationLocation; bool isLexicallyScoped() const { return this->scope != QQmlJS::AST::VariableScope::Var; } bool requiresTDZCheck(const QQmlJS::SourceLocation &accessLocation, bool accessAcrossContextBoundaries) const; @@ -331,7 +331,7 @@ struct Context { } bool addLocalVar(const QString &name, MemberType contextType, QQmlJS::AST::VariableScope scope, QQmlJS::AST::FunctionExpression *function = nullptr, - const QQmlJS::SourceLocation &endOfInitializer = QQmlJS::SourceLocation()); + const QQmlJS::SourceLocation &declarationLocation = QQmlJS::SourceLocation()); struct ResolvedName { enum Type { @@ -348,7 +348,7 @@ struct Context { bool requiresTDZCheck = false; int scope = -1; int index = -1; - QQmlJS::SourceLocation endOfDeclarationLocation; + QQmlJS::SourceLocation declarationLocation; bool isValid() const { return type != Unresolved; } }; ResolvedName resolveName(const QString &name, const QQmlJS::SourceLocation &accessLocation); |