diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-04 06:04:15 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-04 06:04:59 (GMT) |
commit | 57d68b06c15f8426c25e357f97b9154056969e0f (patch) | |
tree | cdd224b86ea9bbead3f92563aadae34285885db6 | |
parent | 5599ddd113fe1385e7a6aff708e12af419b8de87 (diff) | |
download | Qt-57d68b06c15f8426c25e357f97b9154056969e0f.zip Qt-57d68b06c15f8426c25e357f97b9154056969e0f.tar.gz Qt-57d68b06c15f8426c25e357f97b9154056969e0f.tar.bz2 |
Improve grouped property error messages
QT-2579
12 files changed, 48 insertions, 9 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 7a3dde9..32c746f 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1789,13 +1789,19 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr Q_ASSERT(prop->type != 0); Q_ASSERT(prop->index != -1); - if (prop->values.count()) - COMPILE_EXCEPTION(prop->values.first(), QCoreApplication::translate("QDeclarativeCompiler", "Invalid value in grouped property")); - if (QDeclarativeValueTypeFactory::isValueType(prop->type)) { QDeclarativeEnginePrivate *ep = static_cast<QDeclarativeEnginePrivate *>(QObjectPrivate::get(engine)); if (prop->type >= 0 /* QVariant == -1 */ && ep->valueTypes[prop->type]) { + + if (prop->values.count()) { + if (prop->values.at(0)->location < prop->value->location) { + COMPILE_EXCEPTION(prop->value, QCoreApplication::translate("QDeclarativeCompiler", "Property has already been assigned a value")); + } else { + COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Property has already been assigned a value")); + } + } + COMPILE_CHECK(buildValueTypeProperty(ep->valueTypes[prop->type], prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); @@ -1810,6 +1816,9 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr if (!prop->value->metatype) COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid grouped property access")); + if (prop->values.count()) + COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Cannot assign a value directly to a grouped property")); + obj->addGroupedProperty(prop); COMPILE_CHECK(buildSubObject(prop->value, ctxt.incr())); diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index 0e3d856..b0599ad 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -226,9 +226,9 @@ QDeclarativeParser::Property::~Property() if (value) value->release(); } -Object *QDeclarativeParser::Property::getValue() +Object *QDeclarativeParser::Property::getValue(const LocationSpan &l) { - if (!value) value = new Object; + if (!value) { value = new Object; value->location = l; } return value; } diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index d0d7de1..5bf4b68 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -104,6 +104,11 @@ namespace QDeclarativeParser Location start; Location end; LocationRange range; + + bool operator<(LocationSpan &o) const { + return (start.line < o.start.line) || + (start.line == o.start.line && start.column < o.start.column); + } }; class Property; @@ -318,7 +323,7 @@ namespace QDeclarativeParser // The Object to which this property is attached Object *parent; - Object *getValue(); + Object *getValue(const LocationSpan &); void addValue(Value *v); void addOnValue(Value *v); diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index a4b3668..fe516c5 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -85,8 +85,8 @@ class ProcessAST: protected AST::Visitor { const State &state = top(); if (state.property) { - State s(state.property->getValue(), - state.property->getValue()->getProperty(name.toUtf8())); + State s(state.property->getValue(location), + state.property->getValue(location)->getProperty(name.toUtf8())); s.property->location = location; push(s); } else { diff --git a/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt index 945d51b..32055f6 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/defaultGrouped.errors.txt @@ -1 +1 @@ -7:9:Invalid value in grouped property +7:9:Cannot assign a value directly to a grouped property diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt new file mode 100644 index 0000000..1fcb1b6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.errors.txt @@ -0,0 +1 @@ +4:14:Cannot assign a value directly to a grouped property diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml new file mode 100644 index 0000000..41aa3e2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.10.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + grouped: "10x10" + grouped.value: 10 +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt new file mode 100644 index 0000000..fa0da21 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.errors.txt @@ -0,0 +1 @@ +5:19:Property has already been assigned a value diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml new file mode 100644 index 0000000..56fca9b --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.8.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + pointProperty: "10x10" + pointProperty.x: 10 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt new file mode 100644 index 0000000..6d837a7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.errors.txt @@ -0,0 +1 @@ +5:20:Property has already been assigned a value diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml new file mode 100644 index 0000000..982ab26 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidGroupedProperty.9.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + pointProperty.x: 10 + pointProperty: "10x10" +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 5d480fa..28daf29 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -255,6 +255,9 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("invalidGroupedProperty.5") << "invalidGroupedProperty.5.qml" << "invalidGroupedProperty.5.errors.txt" << false; QTest::newRow("invalidGroupedProperty.6") << "invalidGroupedProperty.6.qml" << "invalidGroupedProperty.6.errors.txt" << false; QTest::newRow("invalidGroupedProperty.7") << "invalidGroupedProperty.7.qml" << "invalidGroupedProperty.7.errors.txt" << true; + QTest::newRow("invalidGroupedProperty.8") << "invalidGroupedProperty.8.qml" << "invalidGroupedProperty.8.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.9") << "invalidGroupedProperty.9.qml" << "invalidGroupedProperty.9.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.10") << "invalidGroupedProperty.10.qml" << "invalidGroupedProperty.10.errors.txt" << false; QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false; QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false; |