diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2022-04-01 14:21:02 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-04-01 20:58:49 +0200 |
| commit | c12f0f07f577d4a2c58fd139d0ca0b7aac39fda9 (patch) | |
| tree | 688ff7b944812515959785a46628b62046489efc /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 3827b7039df47e756bdee7ebe4e5bb481cad081d (diff) | |
QmlCompiler: Improve ambiguous type detection
When detecting an ambiguous type, we need to invalidate the entry in the
list of types, rather than delete it. If we delete it and we get yet
another version of the type, we'll add that one just like it was not
ambiguous.
Furthermore, we cannot check the type name when looking for ambiguity.
The QML name can be bent and twisted in various ways, to import
ambiguous-looking types under different names, so that they are actually
not ambiguous.
Pick-to: 6.2 6.3
Fixes: QTBUG-102153
Change-Id: Iee7951229c5f68b168899e55164e8cf91587eec1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 3187ac8d86..3af0ebe6da 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -128,6 +128,7 @@ private slots: void fallbackLookups(); void typedArray(); void prefixedMetaType(); + void evadingAmbiguity(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1959,6 +1960,28 @@ void tst_QmlCppCodegen::prefixedMetaType() QVERIFY(qvariant_cast<QObject *>(o->property("f")) == nullptr); } +void tst_QmlCppCodegen::evadingAmbiguity() +{ + QQmlEngine engine; + + // We need to add an import path here because we cannot namespace the implicit import. + // The implicit import is what we use for all the other tests, even if we explicitly + // import TestTypes. That is because the TestTypes module is in a subdirectory "data". + engine.addImportPath(u":/"_qs); + + QQmlComponent c1(&engine, QUrl(u"qrc:/TestTypes/ambiguous1/Ambiguous.qml"_qs)); + QVERIFY2(c1.isReady(), qPrintable(c1.errorString())); + QScopedPointer<QObject> o1(c1.create()); + QCOMPARE(o1->objectName(), QStringLiteral("Ambiguous")); + QCOMPARE(o1->property("i").toString(), QStringLiteral("Ambiguous1")); + + QQmlComponent c2(&engine, QUrl(u"qrc:/TestTypes/ambiguous2/Ambiguous.qml"_qs)); + QVERIFY2(c2.isReady(), qPrintable(c2.errorString())); + QScopedPointer<QObject> o2(c2.create()); + QCOMPARE(o2->objectName(), QStringLiteral("Ambiguous")); + QCOMPARE(o2->property("i").toString(), QStringLiteral("Ambiguous2")); +} + void tst_QmlCppCodegen::runInterpreted() { if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER")) |
