diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-25 11:01:17 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-03-03 13:35:48 +0100 |
commit | 8272eef2d736351d2ba41590680da395647a874e (patch) | |
tree | 41f2d906b84fd2ae2394a3414b3ce0d82cbd8dbc | |
parent | cf3534147f55ec5f3e5af1f206122c1a5b96ddd4 (diff) |
QmlCompiler: Correctly label return types of JS functions
Returning void from any JS function doesn't quite cut it.
Fixes: QTBUG-101285
Change-Id: I199813627614061ec25139277e8ea23cb844aac5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
(cherry picked from commit 23ab2e0f5552bb54fef5a6c57f5f82f430d0956c)
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/isnan.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 21 |
5 files changed, 35 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index 6222b8acb1..5945aa4584 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -906,7 +906,9 @@ void QQmlJSTypePropagator::propagateCall(const QList<QQmlJSMetaMethod> &methods, return; } - const auto returnType = match.returnType(); + const auto returnType = match.isJavaScriptFunction() + ? m_typeResolver->jsValueType() + : QQmlJSScope::ConstPtr(match.returnType()); m_state.accumulatorOut = m_typeResolver->globalType( returnType ? QQmlJSScope::ConstPtr(returnType) : m_typeResolver->voidType()); if (!m_state.accumulatorOut.isValid()) diff --git a/tests/auto/qml/qmlcppcodegen/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/CMakeLists.txt index 4c4cf0b1e5..946fa38e44 100644 --- a/tests/auto/qml/qmlcppcodegen/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/CMakeLists.txt @@ -4,7 +4,7 @@ qt_internal_add_test(tst_qmlcppcodegen SOURCES tst_qmlcppcodegen.cpp LIBRARIES - Qt::Qml + Qt::QmlPrivate Qt::Gui codegen_test_module codegen_test_moduleplugin diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 95bc78a96a..3d05ffcf1d 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -76,6 +76,7 @@ set(qml_files intOverflow.qml interactive.qml interceptor.qml + isnan.qml jsMathObject.qml jsimport.qml jsmoduleimport.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/isnan.qml b/tests/auto/qml/qmlcppcodegen/data/isnan.qml new file mode 100644 index 0000000000..dfc64e8002 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/isnan.qml @@ -0,0 +1,9 @@ +import QtQml + +QtObject { + property real good: 10.1 + property real bad: "f" / 10 + + property bool a: isNaN(good) + property bool b: isNaN(bad) +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 2c53e5da08..d1b8565afc 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -23,6 +23,8 @@ #include <data/cppbaseclass.h> #include <data/objectwithmethod.h> +#include <private/qqmlengine_p.h> + #include <QtTest> #include <QtQml> #include <QtGui/qcolor.h> @@ -121,6 +123,7 @@ private slots: void blockComments(); void functionLookup(); void objectInVar(); + void testIsnan(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1825,6 +1828,24 @@ void tst_QmlCppCodegen::objectInVar() QVERIFY(!result); } +void tst_QmlCppCodegen::testIsnan() +{ + QQmlEngine engine; + const QUrl document(u"qrc:/TestTypes/isnan.qml"_qs); + QQmlComponent c(&engine, document); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + QCOMPARE(o->property("good").toDouble(), 10.1); + QVERIFY(qIsNaN(o->property("bad").toDouble())); + const QVariant a = o->property("a"); + QCOMPARE(a.metaType(), QMetaType::fromType<bool>()); + QVERIFY(!a.toBool()); + const QVariant b = o->property("b"); + QCOMPARE(b.metaType(), QMetaType::fromType<bool>()); + QVERIFY(b.toBool()); +} + void tst_QmlCppCodegen::runInterpreted() { if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER")) |