diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-09-15 17:10:08 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-09-18 23:24:23 +0200 |
| commit | ecf78f31908edfd343e9447cfe4ac0b53cbabd18 (patch) | |
| tree | 39f03bfd1ac8586ab9eb8349f3f41e25ab55618d /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 5e0ad461fe79bae7052a51e224d433a2b8b68416 (diff) | |
QmlCompiler: Properly handle uncertain component status
In order to determine whether an ID is visible from a referrer we need
not only determine the component boundaries of the referrer, but also
those of the candidate elements with the respective ID. Rewrite the
logic to have QQmlJSScopesById handle this. It has to iterate the
respective elements anyway and can therefore easily check if one of them
is assigned to an unknown property. It now provides low-level methods
that output all possible candidates for an ID, while also stating the
confidence associated with them. The plain id() and scope() methods only
return results we are actually certain about.
In places where we generate warnings or can allow for some fuzzy
results, we use the low-level methods, since those generally produce
more informative results.
The QML DOM was passing the JavaScript global object as referrer to the
scope() method before. This happened to work but was, of course, wrong.
Make sure that ID elements in the DOM receive a proper QML scope to
avoid that.
Pick-to: 6.10 6.9 6.8
Task-number: QTBUG-140041
Change-Id: I41cf8603ae6a5d5461d3c12d74521e68b5e28ea4
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 90fd5f391c..d8a90309bb 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -146,6 +146,7 @@ private slots: void getOptionalLookupShadowed(); void globals(); void idAccess(); + void idVsMember(); void ignoredFunctionReturn(); void importsFromImportPath(); void inPlaceDecrement(); @@ -2716,6 +2717,19 @@ void tst_QmlCppCodegen::idAccess() QCOMPARE(ttt->objectName(), u"context"_s); } +void tst_QmlCppCodegen::idVsMember() +{ + QQmlEngine engine; + QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/idVsMember.qml"_s)); + QVERIFY2(!component.isError(), component.errorString().toUtf8()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QVERIFY(QRegularExpression(u"QQuickItem\\(0x[0-9a-f]+, \"blub\"\\)"_s) + .match(object->objectName()).hasMatch()); + +} + void tst_QmlCppCodegen::ignoredFunctionReturn() { QQmlEngine engine; |
