diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-01-13 10:16:05 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-16 00:03:05 +0100 |
commit | 74c390d44f133f327fc02b9561fe43a23ff4d3b3 (patch) | |
tree | 16ca7754125292008a9f68c6249ed56e307f88d3 | |
parent | ef1860e8c47a5816b151e5d63dbc0db196f9d0a8 (diff) |
lower case QML components are accepted when used with 'as' import
If an Object Binding is in a namespace, ensure that the Component name
begins with a capital letter.
Task-number:QTBUG-20786
Change-Id: Id4a0c0fdb0c9b9516bea597a4994bb7519339bc9
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
19 files changed, 66 insertions, 6 deletions
diff --git a/src/declarative/qml/qdeclarativescript.cpp b/src/declarative/qml/qdeclarativescript.cpp index cbb2bc2cac..660fa95de2 100644 --- a/src/declarative/qml/qdeclarativescript.cpp +++ b/src/declarative/qml/qdeclarativescript.cpp @@ -679,9 +679,9 @@ ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName, AST::UiObjectInitializer *initializer) { int lastTypeDot = objectType.lastIndexOf(QLatin1Char('.')); - bool isType = !objectType.isEmpty() && - (objectType.at(0).isUpper() || - (lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper())); + + // With no preceding qualification, first char is at (-1 + 1) == 0 + bool isType = !objectType.isEmpty() && objectType.at(lastTypeDot+1).isUpper(); int propertyCount = 0; for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ @@ -701,11 +701,26 @@ ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName, if (!isType) { - if(propertyCount || !currentObject()) { + // Is the identifier qualified by a namespace? + int namespaceLength = 0; + if (lastTypeDot > 0) { + const QString qualifier(objectType.left(lastTypeDot)); + + for (int ii = 0; ii < _parser->_imports.count(); ++ii) { + const QDeclarativeScript::Import &import = _parser->_imports.at(ii); + if (import.qualifier == qualifier) { + // The qualifier is a namespace - expect a type here + namespaceLength = qualifier.length() + 1; + break; + } + } + } + + if (propertyCount || !currentObject() || namespaceLength) { QDeclarativeError error; error.setDescription(QCoreApplication::translate("QDeclarativeParser","Expected type name")); error.setLine(typeLocation.startLine); - error.setColumn(typeLocation.startColumn); + error.setColumn(typeLocation.startColumn + namespaceLength); _parser->_errors << error; return 0; } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.errors.txt new file mode 100644 index 0000000000..eff7c0e6c4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.errors.txt @@ -0,0 +1 @@ +1:1:Expected a qualified name id diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.qml new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.qml @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.2.errors.txt index 4bcc948e92..4bcc948e92 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.errors.txt +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.2.errors.txt diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.2.qml index 427827ca89..427827ca89 100644 --- a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.qml +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.2.qml diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.3.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.3.errors.txt new file mode 100644 index 0000000000..fdce1abf06 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.3.errors.txt @@ -0,0 +1 @@ +3:5:Expected type name diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.3.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.3.qml new file mode 100644 index 0000000000..65e93ed55d --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.3.qml @@ -0,0 +1,4 @@ +import QtQuick 2.0 as Foo + +Foo.foo { +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.4.errors.txt new file mode 100644 index 0000000000..3b90f573a2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.4.errors.txt @@ -0,0 +1 @@ +3:1:Bar.Item - Bar is not a namespace diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.4.qml new file mode 100644 index 0000000000..ba4c8ae1f7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.4.qml @@ -0,0 +1,4 @@ +import QtQuick 2.0 as Foo + +Bar.Item { +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.1.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.1.errors.txt new file mode 100644 index 0000000000..4bcc948e92 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.1.errors.txt @@ -0,0 +1 @@ +1:1:Expected type name diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.1.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.1.qml new file mode 100644 index 0000000000..658b72d9f2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.1.qml @@ -0,0 +1,2 @@ +item { +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.2.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.2.errors.txt new file mode 100644 index 0000000000..fdce1abf06 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.2.errors.txt @@ -0,0 +1 @@ +3:5:Expected type name diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.2.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.2.qml new file mode 100644 index 0000000000..9c83238282 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.2.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 as Foo + +Foo.item { +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.3.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.3.errors.txt new file mode 100644 index 0000000000..208df2b84a --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.3.errors.txt @@ -0,0 +1 @@ +5:9:Expected type name diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.3.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.3.qml new file mode 100644 index 0000000000..2f7027081e --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.3.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 as Foo + +Foo.Item { + + Foo.item { + } +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.4.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.4.errors.txt new file mode 100644 index 0000000000..3b90f573a2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.4.errors.txt @@ -0,0 +1 @@ +3:1:Bar.Item - Bar is not a namespace diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.4.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.4.qml new file mode 100644 index 0000000000..ba4c8ae1f7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidTypeName.4.qml @@ -0,0 +1,4 @@ +import QtQuick 2.0 as Foo + +Bar.Item { +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index ff5de84a28..7af60e4496 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -417,7 +417,6 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("nestedErrors") << "nestedErrors.qml" << "nestedErrors.errors.txt" << false; QTest::newRow("defaultGrouped") << "defaultGrouped.qml" << "defaultGrouped.errors.txt" << false; QTest::newRow("doubleSignal") << "doubleSignal.qml" << "doubleSignal.errors.txt" << false; - QTest::newRow("invalidRoot") << "invalidRoot.qml" << "invalidRoot.errors.txt" << false; QTest::newRow("missingValueTypeProperty") << "missingValueTypeProperty.qml" << "missingValueTypeProperty.errors.txt" << false; QTest::newRow("objectValueTypeProperty") << "objectValueTypeProperty.qml" << "objectValueTypeProperty.errors.txt" << false; QTest::newRow("enumTypes") << "enumTypes.qml" << "enumTypes.errors.txt" << false; @@ -442,6 +441,16 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("metaobjectRevision.2") << "metaobjectRevision.2.qml" << "metaobjectRevision.2.errors.txt" << false; QTest::newRow("metaobjectRevision.3") << "metaobjectRevision.3.qml" << "metaobjectRevision.3.errors.txt" << false; + QTest::newRow("invalidRoot.1") << "invalidRoot.1.qml" << "invalidRoot.1.errors.txt" << false; + QTest::newRow("invalidRoot.2") << "invalidRoot.2.qml" << "invalidRoot.2.errors.txt" << false; + QTest::newRow("invalidRoot.3") << "invalidRoot.3.qml" << "invalidRoot.3.errors.txt" << false; + QTest::newRow("invalidRoot.4") << "invalidRoot.4.qml" << "invalidRoot.4.errors.txt" << false; + + QTest::newRow("invalidTypeName.1") << "invalidTypeName.1.qml" << "invalidTypeName.1.errors.txt" << false; + QTest::newRow("invalidTypeName.2") << "invalidTypeName.2.qml" << "invalidTypeName.2.errors.txt" << false; + QTest::newRow("invalidTypeName.3") << "invalidTypeName.3.qml" << "invalidTypeName.3.errors.txt" << false; + QTest::newRow("invalidTypeName.4") << "invalidTypeName.4.qml" << "invalidTypeName.4.errors.txt" << false; + QTest::newRow("Major version isolation") << "majorVersionIsolation.qml" << "majorVersionIsolation.errors.txt" << false; } diff --git a/tests/auto/declarative/qmlmin/tst_qmlmin.cpp b/tests/auto/declarative/qmlmin/tst_qmlmin.cpp index 69ec0cb199..016c799115 100644 --- a/tests/auto/declarative/qmlmin/tst_qmlmin.cpp +++ b/tests/auto/declarative/qmlmin/tst_qmlmin.cpp @@ -103,6 +103,7 @@ void tst_qmlmin::initTestCase() invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/missingObject.qml"; invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/insertedSemicolon.1.qml"; invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/nonexistantProperty.5.qml"; + invalidFiles << "tests/auto/declarative/qdeclarativelanguage/data/invalidRoot.1.qml"; invalidFiles << "tests/auto/declarative/qdeclarativefolderlistmodel/data/dummy.qml"; invalidFiles << "tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22843.js"; invalidFiles << "tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22843.library.js"; |