From 22eaa614ea86c5f823e3de17efa1e43635b52ca7 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 17 Oct 2023 14:06:32 +0200 Subject: QmlCompiler: Reject calls to one of multiple fuzzy overloads If we cannot statically determine the right overload better don't call any of them for now. Also, allow attempts to pass arguments as derived types during type propagation. The test shows that we don't properly pass the thisObject when calling with metatypes. Fix that, too. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-117922 Change-Id: I02e70ffb9a05f3cfedccafde6e16170b0efbcd29 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmlcppcodegen/data/childobject.qml | 1 + tests/auto/qml/qmlcppcodegen/data/objectwithmethod.h | 3 +++ tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 2 ++ 3 files changed, 6 insertions(+) (limited to 'tests/auto/qml/qmlcppcodegen') diff --git a/tests/auto/qml/qmlcppcodegen/data/childobject.qml b/tests/auto/qml/qmlcppcodegen/data/childobject.qml index 7d73e4fd7f..db6b910ec2 100644 --- a/tests/auto/qml/qmlcppcodegen/data/childobject.qml +++ b/tests/auto/qml/qmlcppcodegen/data/childobject.qml @@ -8,6 +8,7 @@ QtObject { function doString() { overloaded("string"); } function doNumber() { overloaded(5.2); } function doArray() { overloaded({a: 2, b: 3, c: 3}); } + function doFoo() { foo(this); } } objectName: child.objectName property int doneThing: child.doThing() diff --git a/tests/auto/qml/qmlcppcodegen/data/objectwithmethod.h b/tests/auto/qml/qmlcppcodegen/data/objectwithmethod.h index 3ecb6d398b..ee01d2a0d2 100644 --- a/tests/auto/qml/qmlcppcodegen/data/objectwithmethod.h +++ b/tests/auto/qml/qmlcppcodegen/data/objectwithmethod.h @@ -32,6 +32,9 @@ public: Q_INVOKABLE void overloaded(QQmlV4Function *) { setObjectName(QStringLiteral("javaScript")); } Q_INVOKABLE void overloaded(double) { setObjectName(QStringLiteral("double")); } Q_INVOKABLE void overloaded(const QString &) { setObjectName(QStringLiteral("string")); } + + Q_INVOKABLE void foo(const QString &bla) { setObjectName(bla); } + Q_INVOKABLE void foo(ObjectWithMethod *) { setObjectName(QStringLiteral("ObjectWithMethod")); } }; class OverriddenObjectName : public ObjectWithMethod diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 3496ca25dd..486a777fef 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -3341,6 +3341,8 @@ void tst_QmlCppCodegen::overriddenProperty() QCOMPARE(child->objectName(), u"double"_s); QMetaObject::invokeMethod(child, "doArray"); QCOMPARE(child->objectName(), u"javaScript"_s); + QMetaObject::invokeMethod(child, "doFoo"); + QCOMPARE(child->objectName(), u"ObjectWithMethod"_s); ObjectWithMethod *benign = new ObjectWithMethod(object.data()); benign->theThing = 10; -- cgit v1.2.3