aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2012-01-06 12:16:24 +0000
committerQt by Nokia <qt-info@nokia.com>2012-01-06 15:27:10 +0100
commit0888e4397e95c08d67814eb860d24d1791b876bd (patch)
tree818b3c97c9cc19e3318682f2236511d3827dc53e
parentafbcb4fd4e3f22eac1b68fb9f44b8492c265d9f0 (diff)
Improve QML error messages
Point at the actual property and method name when raising errors about them. Change-Id: Id36df4850b91ae0d225fcda4d101f4b2a073a72e Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp31
-rw-r--r--src/declarative/qml/qdeclarativescript.cpp4
-rw-r--r--src/declarative/qml/qdeclarativescript_p.h1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.2.errors.txt2
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.4.errors.txt2
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt2
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt2
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt2
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt2
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp2
10 files changed, 32 insertions, 18 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 1bd714bd17..3a7a6013e6 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -185,18 +185,20 @@ bool QDeclarativeCompiler::isSignalPropertyName(const QHashedStringRef &name)
COMPILE_EXCEPTION(property, tr("Error for property \"%1\"").arg(property->name));
\endcode
*/
-#define COMPILE_EXCEPTION(token, desc) \
+#define COMPILE_EXCEPTION_LOCATION(line, column, desc) \
{ \
- QString exceptionDescription; \
QDeclarativeError error; \
error.setUrl(output->url); \
- error.setLine((token)->location.start.line); \
- error.setColumn((token)->location.start.column); \
+ error.setLine(line); \
+ error.setColumn(column); \
error.setDescription(desc.trimmed()); \
exceptions << error; \
return false; \
}
+#define COMPILE_EXCEPTION(token, desc) \
+ COMPILE_EXCEPTION_LOCATION((token)->location.start.line, (token)->location.start.column, desc)
+
/*!
\macro COMPILE_CHECK
\internal
@@ -2641,16 +2643,25 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeScript::Object *obj)
if (propNames.testAndSet(prop.name.hash())) {
for (Object::DynamicProperty *p2 = obj->dynamicProperties.first(); p2 != p;
p2 = obj->dynamicProperties.next(p2)) {
- if (p2->name == prop.name)
- COMPILE_EXCEPTION(&prop, tr("Duplicate property name"));
+ if (p2->name == prop.name) {
+ COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line,
+ prop.nameLocation.column,
+ tr("Duplicate property name"));
+ }
}
}
- if (prop.name.at(0).isUpper())
- COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter"));
+ if (prop.name.at(0).isUpper()) {
+ COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line,
+ prop.nameLocation.column,
+ tr("Property names cannot begin with an upper case letter"));
+ }
- if (enginePrivate->v8engine()->illegalNames().contains(prop.name))
- COMPILE_EXCEPTION(&prop, tr("Illegal property name"));
+ if (enginePrivate->v8engine()->illegalNames().contains(prop.name)) {
+ COMPILE_EXCEPTION_LOCATION(prop.nameLocation.line,
+ prop.nameLocation.column,
+ tr("Illegal property name"));
+ }
}
for (Object::DynamicSignal *s = obj->dynamicSignals.first(); s; s = obj->dynamicSignals.next(s)) {
diff --git a/src/declarative/qml/qdeclarativescript.cpp b/src/declarative/qml/qdeclarativescript.cpp
index 1a60893dcd..cbb2bc2cac 100644
--- a/src/declarative/qml/qdeclarativescript.cpp
+++ b/src/declarative/qml/qdeclarativescript.cpp
@@ -1032,6 +1032,8 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
property->isDefaultProperty = node->isDefaultMember;
property->isReadOnly = node->isReadonlyMember;
property->type = type;
+ property->nameLocation.line = node->identifierToken.startLine;
+ property->nameLocation.column = node->identifierToken.startColumn;
if (type >= Object::DynamicProperty::Custom) {
QDeclarativeScript::TypeReference *typeRef =
_parser->findOrCreateType(memberType.toString());
@@ -1218,7 +1220,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node)
if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) {
Object::DynamicSlot *slot = _parser->_pool.New<Object::DynamicSlot>();
- slot->location = location(funDecl->firstSourceLocation(), funDecl->lastSourceLocation());
+ slot->location = location(funDecl->identifierToken, funDecl->lastSourceLocation());
AST::FormalParameterList *f = funDecl->formals;
while (f) {
diff --git a/src/declarative/qml/qdeclarativescript_p.h b/src/declarative/qml/qdeclarativescript_p.h
index 79b08b6d28..4063c3ba95 100644
--- a/src/declarative/qml/qdeclarativescript_p.h
+++ b/src/declarative/qml/qdeclarativescript_p.h
@@ -401,6 +401,7 @@ public:
QHashedStringRef name;
QDeclarativeScript::Property *defaultValue;
LocationSpan location;
+ Location nameLocation;
// Used by Object::DynamicPropertyList
DynamicProperty *nextProperty;
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.2.errors.txt
index 7a4f63bf0e..713d5f6272 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.2.errors.txt
+++ b/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.2.errors.txt
@@ -1 +1 @@
-5:5:Duplicate property name
+5:19:Duplicate property name
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.4.errors.txt
index 18e07456ef..028e25c37f 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.4.errors.txt
+++ b/tests/auto/declarative/qdeclarativelanguage/data/dynamicMeta.4.errors.txt
@@ -1 +1 @@
-5:5:Duplicate method name
+5:14:Duplicate method name
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt
index c83e5ae1e0..e9e27c479b 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt
+++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt
@@ -1 +1 @@
-4:5:Illegal property name
+4:18:Illegal property name
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt
index 0dab632ff6..98d0b9cefb 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt
+++ b/tests/auto/declarative/qdeclarativelanguage/data/method.1.errors.txt
@@ -1 +1 @@
-4:5:Method names cannot begin with an upper case letter
+4:14:Method names cannot begin with an upper case letter
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt
index 9e8d45448f..985c083cc3 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt
+++ b/tests/auto/declarative/qdeclarativelanguage/data/property.6.errors.txt
@@ -1 +1 @@
-4:5:Property names cannot begin with an upper case letter
+4:18:Property names cannot begin with an upper case letter
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt
index 9e8d45448f..985c083cc3 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt
+++ b/tests/auto/declarative/qdeclarativelanguage/data/property.7.errors.txt
@@ -1 +1 @@
-4:5:Property names cannot begin with an upper case letter
+4:18:Property names cannot begin with an upper case letter
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index fa13e69685..6a03af503f 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -429,7 +429,7 @@ void tst_qdeclarativeqt::createQmlObject()
QString warning1 = component.url().toString() + ":7: Error: Qt.createQmlObject(): Invalid arguments";
QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("inline").toString() + ":2:10: Blah is not a type";
- QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("main.qml").toString() + ":4:1: Duplicate property name";
+ QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("main.qml").toString() + ":4:14: Duplicate property name";
QString warning4 = component.url().toString()+ ":9: Error: Qt.createQmlObject(): Missing parent object";
QString warning5 = component.url().toString()+ ":8: Error: Qt.createQmlObject(): Invalid arguments";
QString warning6 = "RunTimeError: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("inline").toString() + ":3: Cannot assign object type QObject with no default method";