aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/parser/qqmljs.g4
-rw-r--r--tests/auto/qml/qqmlecmascript/data/anonymousFunctionReturnTypeAnnotationIsPreserved.qml5
-rw-r--r--tests/auto/qml/qqmlecmascript/data/namedFunctionExpressionReturnTypeIsPreserved.qml5
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp33
4 files changed, 45 insertions, 2 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index df134d6cdd..f89e0a44e9 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -4046,7 +4046,7 @@ FunctionExpression: T_FUNCTION BindingIdentifier T_LPAREN FormalParameters T_RPA
if (!ensureNoFunctionTypeAnnotations(sym(6).TypeAnnotation, sym(4).FormalParameterList))
return false;
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(stringRef(2), sym(4).FormalParameterList, sym(8).StatementList,
- /*type annotation*/nullptr);
+ sym(6).TypeAnnotation);
node->functionToken = loc(1);
if (! stringRef(2).isNull())
node->identifierToken = loc(2);
@@ -4064,7 +4064,7 @@ FunctionExpression: T_FUNCTION T_LPAREN FormalParameters T_RPAREN TypeAnnotation
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
- /*type annotation*/nullptr);
+ sym(5).TypeAnnotation);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
diff --git a/tests/auto/qml/qqmlecmascript/data/anonymousFunctionReturnTypeAnnotationIsPreserved.qml b/tests/auto/qml/qqmlecmascript/data/anonymousFunctionReturnTypeAnnotationIsPreserved.qml
new file mode 100644
index 0000000000..5ad8ebd4e8
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/anonymousFunctionReturnTypeAnnotationIsPreserved.qml
@@ -0,0 +1,5 @@
+import QtQml
+
+QtObject {
+ property var func: function (): int { return 0; }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/namedFunctionExpressionReturnTypeIsPreserved.qml b/tests/auto/qml/qqmlecmascript/data/namedFunctionExpressionReturnTypeIsPreserved.qml
new file mode 100644
index 0000000000..91121d6861
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/namedFunctionExpressionReturnTypeIsPreserved.qml
@@ -0,0 +1,5 @@
+import QtQml
+
+QtObject {
+ property var func: function foo(): int { return 0; }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 4d6aef7bb5..058393f09f 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -440,6 +440,9 @@ private slots:
void jittedJavaScriptExpressionDoesNotCrashOnExceptionBeingThrown();
+ void anonymousFunctionReturnTypeAnnotationIsPreserved();
+ void namedFunctionExpressionReturnTypeIsPreserved();
+
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
static void verifyContextLifetime(const QQmlRefPointer<QQmlContextData> &ctxt);
@@ -10753,6 +10756,36 @@ void tst_qqmlecmascript::jittedJavaScriptExpressionDoesNotCrashOnExceptionBeingT
QTRY_VERIFY(!timer->isRunning());
}
+void tst_qqmlecmascript::anonymousFunctionReturnTypeAnnotationIsPreserved() {
+ QQmlEngine engine;
+
+ QQmlComponent c(&engine, testFileUrl("anonymousFunctionReturnTypeAnnotationIsPreserved.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY2(o, qPrintable(c.errorString()));
+
+ QJSValue func = o->property("func").value<QJSValue>();
+ auto signature = QJSValuePrivate::asManagedType<QV4::JavaScriptFunctionObject>(&func)->d()->function->jsTypedFunction.types;
+
+ QVERIFY(!signature.empty());
+ QCOMPARE(signature.first(), QQmlMetaType::qmlType(QMetaType::fromType<int>()));
+}
+
+void tst_qqmlecmascript::namedFunctionExpressionReturnTypeIsPreserved() {
+ QQmlEngine engine;
+
+ QQmlComponent c(&engine, testFileUrl("namedFunctionExpressionReturnTypeIsPreserved.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY2(o, qPrintable(c.errorString()));
+
+ QJSValue func = o->property("func").value<QJSValue>();
+ auto signature = QJSValuePrivate::asManagedType<QV4::JavaScriptFunctionObject>(&func)->d()->function->jsTypedFunction.types;
+
+ QVERIFY(!signature.empty());
+ QCOMPARE(signature.first(), QQmlMetaType::qmlType(QMetaType::fromType<int>()));
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"