qmllint: Allow assigning to readonly properties in same scope
If the property lives in the same scope where it's assigned we can assign it even if it's readonly. That's the whole point of it being readonly. Pick-to: 6.2 Change-Id: I172d5b997641490201a0216fd7ebb5a3de30a63b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
b66db710e5
commit
d2507f2383
|
@ -532,7 +532,7 @@ void QQmlJSTypePropagator::generate_StoreNameSloppy(int nameIndex)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!type.isWritable()) {
|
||||
if (!type.isWritable() && !m_currentScope->hasOwnProperty(name)) {
|
||||
setError(u"Can't assign to read-only property %1"_qs.arg(name));
|
||||
|
||||
m_logger->logWarning(u"Cannot assign to read-only property %1"_qs.arg(name), Log_Property,
|
||||
|
|
|
@ -135,9 +135,11 @@ void QQmlJSTypeResolver::init(QQmlJSImportVisitor &visitor)
|
|||
if (!binding.isLiteralBinding())
|
||||
continue;
|
||||
|
||||
if (QQmlJSMetaProperty property = scope->property(binding.propertyName());
|
||||
property.isValid()) {
|
||||
if (!property.isWritable()) {
|
||||
const QQmlJSMetaProperty property = scope->property(binding.propertyName());
|
||||
if (property.isValid()) {
|
||||
// If the property is defined in the same scope where it is set,
|
||||
// we are in fact allowed to set it, even if it's not writable.
|
||||
if (!property.isWritable() && !scope->hasOwnProperty(binding.propertyName())) {
|
||||
m_logger->logWarning(u"Cannot assign to read-only property %1"_qs
|
||||
.arg(binding.propertyName()),
|
||||
Log_Type, binding.sourceLocation());
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import QtQml
|
||||
|
||||
QtObject {
|
||||
readonly property int i: 14
|
||||
}
|
|
@ -853,6 +853,7 @@ void TestQmllint::cleanQmlCode_data()
|
|||
QTest::newRow("GoodModulePrefix") << QStringLiteral("goodModulePrefix.qml");
|
||||
QTest::newRow("required property in Component") << QStringLiteral("requiredPropertyInComponent.qml");
|
||||
QTest::newRow("bytearray") << QStringLiteral("bytearray.qml");
|
||||
QTest::newRow("initReadonly") << QStringLiteral("initReadonly.qml");
|
||||
}
|
||||
|
||||
void TestQmllint::cleanQmlCode()
|
||||
|
|
Loading…
Reference in New Issue