diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2025-03-18 17:30:57 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-04-15 07:19:22 +0000 |
| commit | 9232a7e3b011c7b0ee32be17bf6a3d147544b424 (patch) | |
| tree | 0eac0f2124db3d0169bdf231648b12159e30719b | |
| parent | 12258bc0d375d46fe76a68dda51906f998cc6a5d (diff) | |
qmllint: Do not warn about required properties in grouped property scopes
If a type with required properties is accessed via a grouped scope, we
can't know whether the object already exists, or whether it would need
to be created.
Avoid false positives and don't emit a warning when we encounter a
grouped property scope, or any non-QML scope. Non-grouped, non-QML
scopes should not trigger the issue, but don't need to be checked
either, avoiding some needless work.
As a drive-by change, don't put spaces into a data test tag (which does
not play nice with running the test separately).
Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07
Pick-to: 6.5
Fixes: QTBUG-134887
Change-Id: I747239c5d72993cf9a1563c875cefaf89c8e52a2
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
(cherry picked from commit 2c35772646eb840b8ffceb2812725a2f03d554e8)
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
| -rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 3 | ||||
| -rw-r--r-- | tests/auto/qml/qmllint/data/requiredPropertyInGroupedPropertyScope.qml | 10 | ||||
| -rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 3 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 42e840d4f4..9ea5694ee4 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -1025,7 +1025,8 @@ void QQmlJSImportVisitor::checkRequiredProperties() for (const auto &[_, defScope] : m_scopesByIrLocation.asKeyValueRange()) { if (defScope->parentScope() == m_globalScope || defScope->isInlineComponent() - || defScope->componentRootStatus() != QQmlJSScope::IsComponentRoot::No) { + || defScope->componentRootStatus() != QQmlJSScope::IsComponentRoot::No + || defScope->scopeType() != QQmlSA::ScopeType::QMLScope) { continue; } diff --git a/tests/auto/qml/qmllint/data/requiredPropertyInGroupedPropertyScope.qml b/tests/auto/qml/qmllint/data/requiredPropertyInGroupedPropertyScope.qml new file mode 100644 index 0000000000..ba8d37cb10 --- /dev/null +++ b/tests/auto/qml/qmllint/data/requiredPropertyInGroupedPropertyScope.qml @@ -0,0 +1,10 @@ +import QtQuick + +Item { + id: root + required property int i + + PropertyChanges { + root.width: 100 + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index d7fbb3c9cc..38ee7cbabe 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -1467,7 +1467,8 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("QQmlEasingEnums::Type") << QStringLiteral("animationEasing.qml"); QTest::newRow("ValidLiterals") << QStringLiteral("validLiterals.qml"); QTest::newRow("GoodModulePrefix") << QStringLiteral("goodModulePrefix.qml"); - QTest::newRow("required property in Component") << QStringLiteral("requiredPropertyInComponent.qml"); + QTest::newRow("required_property_in_Component") << QStringLiteral("requiredPropertyInComponent.qml"); + QTest::newRow("requiredPropertyInGroupedPropertyScope") << QStringLiteral("requiredPropertyInGroupedPropertyScope.qml"); QTest::newRow("bytearray") << QStringLiteral("bytearray.qml"); QTest::newRow("initReadonly") << QStringLiteral("initReadonly.qml"); QTest::newRow("connectionNoParent") << QStringLiteral("connectionNoParent.qml"); // QTBUG-97600 |
