diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp index 5f00e3a578..2b42941039 100644 --- a/src/qmlcompiler/qqmljsimporter.cpp +++ b/src/qmlcompiler/qqmljsimporter.cpp @@ -310,8 +310,14 @@ void QQmlJSImporter::importDependencies(const QQmlJSImporter::Import &import, static bool isVersionAllowed(const QQmlJSScope::Export &exportEntry, const QQmlJSScope::Import &importDescription) { - return !importDescription.version().isValid() - || exportEntry.version() <= importDescription.version(); + const QTypeRevision importVersion = importDescription.version(); + const QTypeRevision exportVersion = exportEntry.version(); + if (!importVersion.hasMajorVersion()) + return true; + if (importVersion.majorVersion() != exportVersion.majorVersion()) + return false; + return !importVersion.hasMinorVersion() + || exportVersion.minorVersion() <= importVersion.minorVersion(); } void QQmlJSImporter::processImport(const QQmlJSScope::Import &importDescription, diff --git a/tests/auto/qml/qmllint/data/onlyMajorVersion.qml b/tests/auto/qml/qmllint/data/onlyMajorVersion.qml new file mode 100644 index 0000000000..4066f8f097 --- /dev/null +++ b/tests/auto/qml/qmllint/data/onlyMajorVersion.qml @@ -0,0 +1,8 @@ +import QtQuick.Controls 2 as QQC2 + +QQC2.ApplicationWindow { + height: 400 + width: 400 + visible: true + QQC2.Action {} // Action because it appeared in version 2.3 +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 80c3d17d78..a5e906ce9a 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -1215,6 +1215,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("callBase") << QStringLiteral("callBase.qml"); QTest::newRow("propertyWithOn") << QStringLiteral("switcher.qml"); QTest::newRow("constructorProperty") << QStringLiteral("constructorProperty.qml"); + QTest::newRow("onlyMajorVersion") << QStringLiteral("onlyMajorVersion.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tests/auto/qml/qqmljsscope/data/qualifiedName.qml b/tests/auto/qml/qqmljsscope/data/qualifiedName.qml index 93b4050d07..1deb7632c3 100644 --- a/tests/auto/qml/qqmljsscope/data/qualifiedName.qml +++ b/tests/auto/qml/qqmljsscope/data/qualifiedName.qml @@ -3,7 +3,7 @@ import QualifiedNamesTests 5.0 as MyQualifiedImport import QtQuick 2.0 Item { - A {} + // A {} <- QML_REMOVED_IN_VERSION(6, 0) B {} diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp index 94021b488e..09c6601858 100644 --- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp +++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp @@ -686,14 +686,12 @@ void tst_qqmljsscope::qualifiedName() return u""_s; }; - QCOMPARE(root->childScopes().size(), 5); - QQmlJSScope::ConstPtr a = root->childScopes()[0]; - QQmlJSScope::ConstPtr b = root->childScopes()[1]; - QQmlJSScope::ConstPtr d = root->childScopes()[2]; - QQmlJSScope::ConstPtr qualifiedA = root->childScopes()[3]; - QQmlJSScope::ConstPtr qualifiedB = root->childScopes()[4]; + QCOMPARE(root->childScopes().size(), 4); + QQmlJSScope::ConstPtr b = root->childScopes()[0]; + QQmlJSScope::ConstPtr d = root->childScopes()[1]; + QQmlJSScope::ConstPtr qualifiedA = root->childScopes()[2]; + QQmlJSScope::ConstPtr qualifiedB = root->childScopes()[3]; - QCOMPARE(qualifiedNameOf(a), "QualifiedNamesTests/A 5.0"); QCOMPARE(qualifiedNameOf(b), "QualifiedNamesTests/B 5.0-6.0"); QCOMPARE(qualifiedNameOf(d), "QualifiedNamesTests/D 6.0"); QCOMPARE(qualifiedNameOf(qualifiedA), "QualifiedNamesTests/A 5.0");