[new compiler] Fix error reporting when trying to set list properties multiple times
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 20 Feb 2014 11:51:53 +0000 (12:51 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sun, 2 Mar 2014 13:48:13 +0000 (14:48 +0100)
Change-Id: Ifcbed45894b739a57873356e8963670084614880
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qqmlcodegenerator.cpp
src/qml/compiler/qqmlcodegenerator_p.h

index 45d97d4..658413d 100644 (file)
@@ -167,8 +167,8 @@ QString QmlObject::appendBinding(Binding *b, bool isListBinding)
         && !(b->flags & QV4::CompiledData::Binding::IsOnAssignment)) {
         if (bindingNames.contains(b->propertyNameIndex))
             return tr("Property value set multiple times");
-        bindingNames.insert(b->propertyNameIndex);
     }
+    bindingNames.insert(b->propertyNameIndex);
     if (isListBinding) {
         bindings->append(b);
     } else if (bindingToDefaultProperty) {
@@ -347,6 +347,13 @@ bool QQmlCodeGenerator::visit(QQmlJS::AST::UiArrayBinding *node)
 
     qSwap(_object, object);
 
+    const int propertyNameIndex = registerString(name->name.toString());
+
+    if (bindingsTarget()->hasBinding(propertyNameIndex)) {
+        recordError(name->identifierToken, tr("Property value set multiple times"));
+        return false;
+    }
+
     QQmlJS::AST::UiArrayMemberList *member = node->members;
     while (member) {
         QQmlJS::AST::UiObjectDefinition *def = QQmlJS::AST::cast<QQmlJS::AST::UiObjectDefinition*>(member->member);
@@ -354,7 +361,7 @@ bool QQmlCodeGenerator::visit(QQmlJS::AST::UiArrayBinding *node)
         int idx = 0;
         if (!defineQMLObject(&idx, def))
             return false;
-        appendBinding(name->identifierToken, registerString(name->name.toString()), idx, /*isListItem*/ true);
+        appendBinding(name->identifierToken, propertyNameIndex, idx, /*isListItem*/ true);
 
         member = member->next;
     }
index 7c5e66d..d8357f2 100644 (file)
@@ -226,6 +226,7 @@ public:
     void appendFunction(QtQml::Function *f);
 
     QString appendBinding(Binding *b, bool isListBinding);
+    bool hasBinding(int nameIndex) const { return bindingNames.contains(nameIndex); }
 
 private:
     PoolList<QmlProperty> *properties;