From 2f653cc06b97b443b9832d0121dbf92b35dd32c2 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 9 Feb 2010 12:32:22 +1000 Subject: Remove old implicit module support. Previously, it was allowed to use type qualification to refer to types defined in subdirectories - indeed, this was the only form of modularity. This is no longer desirable since we have good import features. Task-number: QTBUG-7721 --- src/declarative/qml/qmlcompositetypemanager.cpp | 16 ++++++++++------ src/declarative/qml/qmlengine.cpp | 14 ++++++-------- .../qmllanguage/data/subdir/subsubdir/SubTest.qml | 2 ++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 11 +++++++++++ 4 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 9c78912..3504fe9 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -512,14 +512,18 @@ int QmlCompositeTypeManager::resolveTypes(QmlCompositeTypeData *unit) int majorVersion; int minorVersion; QmlEnginePrivate::ImportedNamespace *typeNamespace = 0; - if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, &typeNamespace)) { - // XXX could produce error message here. - } - - if (typeNamespace) { + if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, &typeNamespace) + || typeNamespace) + { + // Known to not be a type: + // - known to be a namespace (Namespace {}) + // - type with unknown namespace (UnknownNamespace.SomeType {}) QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(tr("Namespace %1 cannot be used as a type").arg(QString::fromUtf8(typeName))); + if (typeNamespace) + error.setDescription(tr("Namespace %1 cannot be used as a type").arg(QString::fromUtf8(typeName))); + else + error.setDescription(tr("%1 is not a type").arg(QString::fromUtf8(typeName))); if (!parserRef->refObjects.isEmpty()) { QmlParser::Object *obj = parserRef->refObjects.first(); error.setLine(obj->location.start.line); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index bb26d30..f4dcb7a 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1276,14 +1276,12 @@ public: QmlEnginePrivate::ImportedNamespace *s = 0; int slash = type.indexOf('/'); if (slash >= 0) { - while (!s) { - s = set.value(QString::fromUtf8(type.left(slash))); - int nslash = type.indexOf('/',slash+1); - if (nslash > 0) - slash = nslash; - else - break; - } + s = set.value(QString::fromUtf8(type.left(slash))); + if (!s) + return false; // qualifier must be a namespace + int nslash = type.indexOf('/',slash+1); + if (nslash > 0) + return false; // only single qualification allowed } else { s = &unqualifiedset; } diff --git a/tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml b/tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml new file mode 100644 index 0000000..c4d5905 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml @@ -0,0 +1,2 @@ +import Qt 4.6 +Rectangle { } diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 606d4c6..357fc5f 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -1187,6 +1187,17 @@ void tst_qmllanguage::importsLocal_data() << "import Qt 4.6\nimport \"subdir\"\n" "Test {}" << "QmlGraphicsRectangle"; + QTest::newRow("local import subsubdir") + << "import Qt 4.6\nimport \"subdir/subsubdir\"\n" + "SubTest {}" + << "QmlGraphicsRectangle"; + QTest::newRow("local import QTBUG-7721 A") + << "subdir.Test {}" // no longer allowed (QTBUG-7721) + << ""; + QTest::newRow("local import QTBUG-7721 B") + << "import \"subdir\" as X\n" + "X.subsubdir.SubTest {}" // no longer allowed (QTBUG-7721) + << ""; QTest::newRow("local import as") << "import \"subdir\" as T\n" "T.Test {}" -- cgit v0.12