diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index 5d3123569f..f3b92fd27f 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -946,7 +946,7 @@ void QQmlCodeGenerator::appendBinding(AST::UiQualifiedId *name, int objectIndex, void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, quint32 propertyNameIndex, AST::Statement *value) { if (stringAt(propertyNameIndex) == QStringLiteral("id")) { - setId(value); + setId(nameLocation, value); return; } @@ -1009,7 +1009,7 @@ QmlObject *QQmlCodeGenerator::bindingsTarget() const return _object; } -bool QQmlCodeGenerator::setId(AST::Statement *value) +bool QQmlCodeGenerator::setId(const AST::SourceLocation &idLocation, AST::Statement *value) { AST::SourceLocation loc = value->firstSourceLocation(); QStringRef str; @@ -1047,6 +1047,9 @@ bool QQmlCodeGenerator::setId(AST::Statement *value) if (illegalNames.contains(idQString)) COMPILE_EXCEPTION(loc, tr( "ID illegally masks global JavaScript property")); + if (_object->idIndex != emptyStringIndex) + COMPILE_EXCEPTION(idLocation, tr("Property value set multiple times")); + _object->idIndex = registerString(idQString); _object->locationOfIdProperty.line = loc.startLine; _object->locationOfIdProperty.column = loc.startColumn; diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index eae359418a..124b46bc9e 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -162,7 +162,7 @@ struct QmlObject Q_DECLARE_TR_FUNCTIONS(QmlObject) public: int inheritedTypeNameIndex; - int idIndex; + quint32 idIndex; int indexOfDefaultProperty; QV4::CompiledData::Location location; @@ -293,7 +293,7 @@ public: QmlObject *bindingsTarget() const; - bool setId(AST::Statement *value); + bool setId(const AST::SourceLocation &idLocation, AST::Statement *value); // resolves qualified name (font.pixelSize for example) and returns the last name along // with the object any right-hand-side of a binding should apply to.