From ab71cdafca87513a4e214d3af056d8990bc1eddb Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 11 Feb 2021 13:17:29 +0100 Subject: 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 --- tests/auto/qml/qmllint/tst_qmllint.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/auto/qml/qmllint/tst_qmllint.cpp') diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 1486a9e1d3..6e2a41263e 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -283,6 +283,11 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("SegFault.bad.qml") << QString() << 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() -- cgit v1.2.3