qmllint: Consider "on-bindings" for required properties
The runtime doesn't complain if a required property is satisfied via a ValueSource or an Interceptor, so qmllint shouldn't complain either. Whether this really should apply to interceptors is debatable, but for now let's aim for consistency. And that a ValueSource can satifsy the requirement is arguably to be expected. Pick-to: 6.10 6.8 Fixes: QTBUG-139632 Change-Id: I355b8a48e6b9bc2749839267c3b799e8eba5d72f Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
This commit is contained in:
parent
9d768789ff
commit
46925f589f
|
@ -1149,7 +1149,11 @@ void QQmlJSImportVisitor::checkRequiredProperties()
|
|||
continue;
|
||||
const auto &[begin, end] = scope->ownPropertyBindings(propName);
|
||||
for (auto it = begin; it != end; ++it) {
|
||||
if (!QQmlSA::isRegularBindingType(it->bindingType()))
|
||||
// attached and grouped bindings should not be considered here
|
||||
const bool isRelevantBinding = QQmlSA::isRegularBindingType(it->bindingType())
|
||||
|| it->bindingType() == QQmlSA::BindingType::Interceptor
|
||||
|| it->bindingType() == QQmlSA::BindingType::ValueSource;
|
||||
if (!isRelevantBinding)
|
||||
continue;
|
||||
if (QQmlJSScope::ownerOfProperty(scope, propName).scope == owner)
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: window
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
|
||||
property int refValue: 0
|
||||
|
||||
component TestObject: QtObject {
|
||||
required property int value
|
||||
}
|
||||
|
||||
|
||||
TestObject {
|
||||
// consistent with runtime
|
||||
Behavior on value {}
|
||||
}
|
||||
|
||||
TestObject {
|
||||
Binding on value {
|
||||
value: 42
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2287,6 +2287,7 @@ void TestQmllint::cleanQmlCode_data()
|
|||
QTest::newRow("qualifiedAttached") << QStringLiteral("Drawer.qml");
|
||||
QTest::addRow("regExp") << u"regExp.qml"_s;
|
||||
QTest::newRow("requiredPropertyInGroupedPropertyScope") << QStringLiteral("requiredPropertyInGroupedPropertyScope.qml");
|
||||
QTest::newRow("requiredPropertySetViaOnBinding") << QStringLiteral("requiredPropertySetViaOnBinding.qml");
|
||||
QTest::newRow("requiredWithRootLevelAlias") << QStringLiteral("RequiredWithRootLevelAlias.qml");
|
||||
QTest::newRow("required_property_in_Component") << QStringLiteral("requiredPropertyInComponent.qml");
|
||||
QTest::newRow("retrieveFunction") << QStringLiteral("retrieveFunction.qml");
|
||||
|
|
Loading…
Reference in New Issue