diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-27 13:09:01 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-28 10:41:52 +0100 |
commit | f9a285daf2033b5393d5b521d27c0cc659515632 (patch) | |
tree | 412c31c4a45847215aa82ed89c48526c9983a216 /src/qml/qml/qqmlobjectcreator.cpp | |
parent | cad0f7e5b9915b1f4579f25121f7b9231405bfa2 (diff) |
[new compiler] Report errors when trying to bind to read-only properties
The only exception are initializers for read-only property declarations.
Also adjusted the error location of one test to point to the correct value
location as opposed to the property location, as with all the other similar
errors.
Change-Id: I2333d3c485fc374b1b39a5f5a4408af5cf08a20f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlobjectcreator.cpp')
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 67c21706c5..bd5a212408 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -594,7 +594,7 @@ void QmlObjectCreator::setupBindings() QString id = stringAt(_compiledObject->idIndex); if (!id.isEmpty()) { QQmlPropertyData *idProperty = _propertyCache->property(QStringLiteral("id"), _qobject, context); - if (idProperty) { + if (idProperty && idProperty->isWritable()) { QV4::CompiledData::Binding idBinding; idBinding.propertyNameIndex = 0; // Not used idBinding.flags = 0; @@ -635,6 +635,17 @@ void QmlObjectCreator::setupBindings() bool QmlObjectCreator::setPropertyValue(QQmlPropertyData *property, int bindingIndex, const QV4::CompiledData::Binding *binding) { + if (property && !property->isWritable() + && !property->isQList() + && binding->type != QV4::CompiledData::Binding::Type_GroupProperty + && !(binding->flags & QV4::CompiledData::Binding::InitializerForReadOnlyDeclaration) + && !(binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) + && !(binding->flags & QV4::CompiledData::Binding::IsOnAssignment) + ) { + recordError(binding->valueLocation, tr("Invalid property assignment: \"%1\" is a read-only property").arg(property->name(_qobject))); + return false; + } + if (binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) { Q_ASSERT(stringAt(qmlUnit->objectAt(binding->value.objectIndex)->inheritedTypeNameIndex).isEmpty()); QQmlCompiledData::TypeReference *tr = resolvedTypes.value(binding->propertyNameIndex); |