From cf01cfb8275c785d21eb5867c968cac1f54d296e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 11 Dec 2009 09:07:49 +1000 Subject: Generate error when attempting to write to a read-only object property. --- src/declarative/qml/qmlcompiler.cpp | 3 +++ tests/auto/declarative/qmllanguage/data/HelperAlias.qml | 9 +++++++++ tests/auto/declarative/qmllanguage/data/readOnly.3.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/readOnly.3.qml | 8 ++++++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 1 + 5 files changed, 22 insertions(+) create mode 100644 tests/auto/declarative/qmllanguage/data/HelperAlias.qml create mode 100644 tests/auto/declarative/qmllanguage/data/readOnly.3.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/readOnly.3.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 108e3cc..f9a9b1b 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1933,6 +1933,9 @@ bool QmlCompiler::buildPropertyObjectAssignment(QmlParser::Property *prop, Q_ASSERT(prop->index != -1); Q_ASSERT(v->object->type != -1); + if (!obj->metaObject()->property(prop->index).isWritable()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); + if (QmlMetaType::isInterface(prop->type)) { // Assigning an object to an interface ptr property diff --git a/tests/auto/declarative/qmllanguage/data/HelperAlias.qml b/tests/auto/declarative/qmllanguage/data/HelperAlias.qml new file mode 100644 index 0000000..dc3b382 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/HelperAlias.qml @@ -0,0 +1,9 @@ +import Test 1.0 +import Qt 4.6 + +QtObject { + property var child + child: QtObject { id: obj } + property alias objAlias: obj; +} + diff --git a/tests/auto/declarative/qmllanguage/data/readOnly.3.errors.txt b/tests/auto/declarative/qmllanguage/data/readOnly.3.errors.txt new file mode 100644 index 0000000..c7e9e1b --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/readOnly.3.errors.txt @@ -0,0 +1 @@ +6:36:Invalid property assignment: "objAlias" is a read-only property diff --git a/tests/auto/declarative/qmllanguage/data/readOnly.3.qml b/tests/auto/declarative/qmllanguage/data/readOnly.3.qml new file mode 100644 index 0000000..cd86a48 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/readOnly.3.qml @@ -0,0 +1,8 @@ +import Test 1.0 +import Qt 4.6 + +QtObject { + property var child + child: HelperAlias { objAlias: QtObject {} } +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 4bca21a..160998f 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -229,6 +229,7 @@ void tst_qmllanguage::errors_data() QTest::newRow("readOnly.1") << "readOnly.1.qml" << "readOnly.1.errors.txt" << false; QTest::newRow("readOnly.2") << "readOnly.2.qml" << "readOnly.2.errors.txt" << false; + QTest::newRow("readOnly.3") << "readOnly.3.qml" << "readOnly.3.errors.txt" << false; QTest::newRow("listAssignment.1") << "listAssignment.1.qml" << "listAssignment.1.errors.txt" << false; QTest::newRow("listAssignment.2") << "listAssignment.2.qml" << "listAssignment.2.errors.txt" << false; -- cgit v0.12