[new compiler] Detect when writing to read-only value type property and bail out
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 3 Mar 2014 11:04:57 +0000 (12:04 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 3 Mar 2014 19:45:04 +0000 (20:45 +0100)
Also annotate QML expressions in the IR with a proper function name, to
make debugging easier.

Change-Id: I5bacf446f40d35896f50bed0732f6f10408d9c97
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qqmlcodegenerator.cpp
src/qml/compiler/qqmltypecompiler.cpp

index 100dc88..87f2651 100644 (file)
@@ -912,7 +912,7 @@ void QQmlCodeGenerator::setBindingValue(QV4::CompiledData::Binding *binding, QQm
 
         CompiledFunctionOrExpression *expr = New<CompiledFunctionOrExpression>();
         expr->node = statement;
-        expr->nameIndex = 0;
+        expr->nameIndex = registerString(QStringLiteral("expression for ") + stringAt(binding->propertyNameIndex));
         expr->disableAcceleratedLookups = false;
         const int index = bindingsTarget()->functionsAndExpressions->append(expr);
         binding->value.compiledScriptIndex = index;
index d79c739..034e576 100644 (file)
@@ -1774,7 +1774,7 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD
 
             if (!pd->isWritable()
                 && !pd->isQList()
-                && binding->type != QV4::CompiledData::Binding::Type_GroupProperty
+                && !binding->isGroupProperty()
                 && !(binding->flags & QV4::CompiledData::Binding::InitializerForReadOnlyDeclaration)
                 ) {
 
@@ -1815,9 +1815,14 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD
             } else if (binding->type == QV4::CompiledData::Binding::Type_Object) {
                 if (!validateObjectBinding(pd, name, binding))
                     return false;
-            } else if (binding->type == QV4::CompiledData::Binding::Type_GroupProperty) {
+            } else if (binding->isGroupProperty()) {
                 if (QQmlValueTypeFactory::isValueType(pd->propType)) {
-                    if (!QQmlValueTypeFactory::valueType(pd->propType)) {
+                    if (QQmlValueTypeFactory::valueType(pd->propType)) {
+                        if (!pd->isWritable()) {
+                            recordError(binding->location, tr("Invalid property assignment: \"%1\" is a read-only property").arg(name));
+                            return false;
+                        }
+                    } else {
                         recordError(binding->location, tr("Invalid grouped property access"));
                         return false;
                     }