summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-04-03 10:15:07 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-05-02 19:29:25 +0200
commit46cc70e2aafc84db6caeaf747629ee6e825b0a4d (patch)
tree6b599a7754efa2877b15cee918006da5242d5a9f /tests/auto
parent961d11e55f3eb1ac2e33eefd80adede01cc62622 (diff)
downloadqtdeclarative-46cc70e2aafc84db6caeaf747629ee6e825b0a4d.tar.gz
QmlCompiler: Relax shadowing check
If we detect a property or method as potentially shadowed, we don't have to abandon all hope. We can still retrieve it as untyped var. Since there are a number of things we can do with untyped var, this may still be useful. In the same sense, we need to treat function calls as untyped when the function in question can be shadowed. Calling functions with var arguments and return types leads to some more interesting situations in the call frame setup, so we fix that, too. Task-number: QTBUG-112480 Change-Id: I238d1cf04951f390c73e14ed9e299f2aa72b68cb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/shadowedMethod.qml35
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp13
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 85ac7e6e2e..48fcf3bec0 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -181,6 +181,7 @@ set(qml_files
scopeVsObject.qml
script.js
script.mjs
+ shadowedMethod.qml
shared/Slider.qml
shifts.qml
signal.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/shadowedMethod.qml b/tests/auto/qml/qmlcppcodegen/data/shadowedMethod.qml
new file mode 100644
index 0000000000..590fb40b17
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/shadowedMethod.qml
@@ -0,0 +1,35 @@
+pragma Strict
+import QtQuick
+
+Item {
+ component B: Item {
+ function contains(point: point) : string {
+ return "b"
+ }
+ }
+
+
+ component C: Item {
+ function contains(point: point) : string {
+ return "c"
+ }
+ }
+
+ property Item a: Item {}
+ property B b: B {}
+ property C c: C {}
+
+ function doThing() : var { return a.contains(Qt.point(0, 0)) }
+
+ property var athing;
+ property var bthing;
+ property var cthing;
+
+ Component.onCompleted: {
+ athing = doThing();
+ a = b;
+ bthing = doThing();
+ a = c;
+ cthing = doThing();
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 25002acd3f..e3292b52f3 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -183,6 +183,7 @@ private slots:
void jsArrayMethods();
void jsArrayMethodsWithParams_data();
void jsArrayMethodsWithParams();
+ void shadowedMethod();
};
void tst_QmlCppCodegen::initTestCase()
@@ -3754,6 +3755,18 @@ void tst_QmlCppCodegen::jsArrayMethodsWithParams()
QCOMPARE(object->property("listPropertyLastIndexOf"), check->property("jsArrayLastIndexOf"));
}
+void tst_QmlCppCodegen::shadowedMethod()
+{
+ QQmlEngine e;
+ QQmlComponent c(&e, QUrl(u"qrc:/qt/qml/TestTypes/shadowedMethod.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->property("athing"), QVariant::fromValue<bool>(false));
+ QCOMPARE(o->property("bthing"), QVariant::fromValue(u"b"_s));
+ QCOMPARE(o->property("cthing"), QVariant::fromValue(u"c"_s));
+}
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"