aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-01-24 14:08:50 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-01-30 15:58:12 +0100
commit07185214ddc593f460b053acd89bbd96b62a2ba5 (patch)
tree570d1f39b6d0511f3ecb204fb2a9db2fa5e8e013
parent9e4f6d92111bff0d422609704673cc0d9a46cafd (diff)
QmlCompiler: Fix version resolution for imports
Partially versioned imports should not be sorted useing the generic comparison operators. We have to check each component individually. Pick-to: 6.5 Fixes: QTBUG-110320 Change-Id: Id75ab73ff6a4b5b040b9fcbb426e6bcf893d3d8b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljsimporter.cpp10
-rw-r--r--tests/auto/qml/qmllint/data/onlyMajorVersion.qml8
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
-rw-r--r--tests/auto/qml/qqmljsscope/data/qualifiedName.qml2
-rw-r--r--tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp14
5 files changed, 24 insertions, 11 deletions
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(qualifiedNameOf(a), "QualifiedNamesTests/A 5.0");
+ 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(b), "QualifiedNamesTests/B 5.0-6.0");
QCOMPARE(qualifiedNameOf(d), "QualifiedNamesTests/D 6.0");
QCOMPARE(qualifiedNameOf(qualifiedA), "QualifiedNamesTests/A 5.0");