diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-11-04 16:54:56 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-11-08 20:49:17 +0100 |
commit | a0290dcc53a14b67c0179c43ce8dc21b43cfc83b (patch) | |
tree | 6144a1569f3943b71d42c365bb6e4866b8f00474 /tests/auto/qml/qqmllanguage/data | |
parent | 50cd61a234e058ea8d9331795944b2d94ec525c6 (diff) |
QML: Fix precedence between imports
So far we have "normal", "low precedence", and "implicit" imports.
Normal imports were ordered in document order, later imports overriding
earlier ones. Low precedence imports were ordered in intractable
confusion, and implicit imports were added last, with the actual
implicit import first, and any dependencies of it after it in
intractable confusion.
Since that gives us problems when QtQml is split into an empty "meta"
module and a number of dependencies, we have to clear out the confusion.
Following the principle that direct imports have higher precedence than
indirect ones, we can give each import a precedence number, depending on
whether it is implicitly imported or not, and how much the importer has
recursed to reach it. Ordering the imports by that number results in a
less confused structure, more accessible to reason.
Also, module imports were added in different order depending on whether
they were revisioned or not. Add them always in the same order.
[ChangeLog][QtQml][Important Behavior Changes] The precedence of imports
that expose different types for the same name has changed. Previously
the algorithm was rather confused. Now, the rule of thumb is that
more direct imports override more indirect ones. That means QtObject
imported directly from QtQml is of higher precedence than QtObject
imported from QtQml via QtQuick. Where that still leaves ambiguities,
imports later in the document override imports earlier in the document.
Any explicit imports and their dependencies always override the implicit
import and its dependencies.
Task-number: QTBUG-105240
Change-Id: I5f95f6bb8367087b9d977cb01f434d01bb402a3e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/data')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/importPrecedenceBad.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/importPrecedenceGood.qml | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/importPrecedenceBad.qml b/tests/auto/qml/qqmllanguage/data/importPrecedenceBad.qml new file mode 100644 index 0000000000..752694d2e3 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/importPrecedenceBad.qml @@ -0,0 +1,12 @@ +import QtQml 2.15 +import QtQml.Models 2.0 + +ListModel { + id: self + + // agent was added in 2.14 and should be invisible + // The QtQml.Models import's qmldir imports should take precedence the QtQml import's + // since it's more direct. + // A QtQuick import would be less direct since it adds one more level of indirection. + property QtObject theAgent: agent +} diff --git a/tests/auto/qml/qqmllanguage/data/importPrecedenceGood.qml b/tests/auto/qml/qqmllanguage/data/importPrecedenceGood.qml new file mode 100644 index 0000000000..c271cf9f95 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/importPrecedenceGood.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import QtQml 2.15 + +ListModel { + id: self + + // agent was added in 2.14 and should be visible + // The QtQml import's qmldir imports should take precedence the QtQuick import's + property QtObject theAgent: agent +} |