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>
This commit is contained in:
Ulf Hermann 2023-01-24 14:08:50 +01:00
parent 9e4f6d9211
commit 07185214dd
5 changed files with 23 additions and 10 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -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()

View File

@ -3,7 +3,7 @@ import QualifiedNamesTests 5.0 as MyQualifiedImport
import QtQuick 2.0
Item {
A {}
// A {} <- QML_REMOVED_IN_VERSION(6, 0)
B {}

View File

@ -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");