aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-11 13:17:29 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-02-12 12:48:08 +0100
commit06d819cd714542427ed9f70820b84004c874a9db (patch)
tree9ec55c5dac1408314b25c587b6b0bfb8ccdf31fb /tests
parente7695ce2ca2e8aa29c8b689f4cdb97e8b8fa43ef (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. Task-number: QTBUG-89943 Change-Id: I8a9424ca8c6edd562402fe5c560ba7e8344b5585 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit ab71cdafca87513a4e214d3af056d8990bc1eddb) Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmllint/data/useBeforeDeclaration.qml8
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp5
2 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/qml/qmllint/data/useBeforeDeclaration.qml b/tests/auto/qml/qmllint/data/useBeforeDeclaration.qml
new file mode 100644
index 0000000000..1c0f8092c3
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/useBeforeDeclaration.qml
@@ -0,0 +1,8 @@
+import QtQml
+QtObject {
+ signal sig()
+ onSig: ()=> {
+ argq = 12;
+ var argq;
+ }
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index b874d3cc6f..97840cc2dd 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -277,6 +277,11 @@ void TestQmllint::dirtyQmlCode_data()
<< QStringLiteral("brokenNamespace.qml")
<< QString("Warning: type not found in namespace at %1:4:17")
<< QString();
+ QTest::newRow("VariableUsedBeforeDeclaration")
+ << QStringLiteral("useBeforeDeclaration.qml")
+ << QStringLiteral("Variable \"argq\" is used before its declaration at 5:9. "
+ "The declaration is at 6:13.")
+ << QString();
}
void TestQmllint::dirtyQmlCode()