diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-10-07 09:21:28 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-10-08 16:00:36 +0200 |
| commit | 95ed95f548cc27edbe063ffb3e3c1d4c1ecb53e9 (patch) | |
| tree | ef3af28c68164f1662a40e167480b11d10d6633b /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 68f2092b13f8956e77c830da4c3fa5e800b15624 (diff) | |
QmlCompiler: Expect singleton members to be shadowable
You can return an instance of a derived class from a singleton's
create() method and that derived class can shadow members of the
singleton. We have no choice but to run many singleton accesses through
the shadow check. There are some exceptions:
1. Extended singletons can't be shadowed since their concrete type
can't be known in advance and the respective QQmlType can't stitch
the metaobjects together to make that happen.
2. Composite singletons can't have factory functions. They also cannot
be shadowed.
3. If the whole class is final. We can't detect that, yet, though.
Pick-to: 6.10
Fixes: QTBUG-140738
Change-Id: Ia6c235636aec723e834db0089a9471f3b0a1e2fa
Reviewed-by: Fabian Kosmale <fabian.kosmale@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 | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 016d4c95a0..9bbe15ca7d 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -258,6 +258,7 @@ private slots: void shadowedAsCasts(); void shadowedMethod(); void shadowedPrimitiveCmpEqNull(); + void shadowingSingleton(); void shifts(); void signalHandler(); void signalIndexMismatch(); @@ -5409,6 +5410,17 @@ void tst_QmlCppCodegen::shadowedPrimitiveCmpEqNull() QVERIFY(!o.isNull()); } +void tst_QmlCppCodegen::shadowingSingleton() +{ + QQmlEngine e; + QQmlComponent c(&e, QUrl(u"qrc:/qt/qml/TestTypes/shadowingSingleton.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + + QCOMPARE(o->objectName(), u"Hej"_s); +} + void tst_QmlCppCodegen::shifts() { QQmlEngine engine; |
