aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-06-21 14:11:41 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-06-26 20:42:49 +0200
commit9eb6240ebd0b7f52ec49aba757a8c355b25203e0 (patch)
treecff2b25ad5798206830bb1cb1ea1c036610634d6 /tests/auto
parenta3389d6bf238c46816fd1133c1258102e36c4b10 (diff)
QML: Improve the JS-to-JS type check when enforcing signatures
We do not have to coerce via the C++ type. Rather, we match the JavaScript representations of the types and coerce as needed. Task-number: QTBUG-113527 Change-Id: Id5c30cd46293f2d7aedd699f141a9fe19511b622 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qqmllanguage/data/signatureEnforced.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp12
2 files changed, 14 insertions, 3 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml b/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml
index e2ddd75b55..ec00d5d2b3 100644
--- a/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml
+++ b/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml
@@ -8,7 +8,7 @@ QtObject {
property withLength withLength: 5
function a(r: rect) {
- r.x = 77 // does not write back
+ r.x = 77 // does write back, but this is an evil thing to do.
}
function b(s: string) : int {
@@ -28,8 +28,11 @@ QtObject {
property int n: c(99) // creates a withLength
property int o: rect.y
+ function bad(b: int) { return b }
+
Component.onCompleted: {
a(rect)
d(rect)
+ bad(15)
}
}
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 9af21af82c..2277e91a47 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -7735,12 +7735,20 @@ void tst_qqmllanguage::functionSignatureEnforcement()
QCOMPARE(ignored->property("m").toInt(), 77);
QCOMPARE(ignored->property("n").toInt(), 67);
- QQmlComponent c2(&engine, testFileUrl("signatureEnforced.qml"));
+ const QUrl url2 = testFileUrl("signatureEnforced.qml");
+ QQmlComponent c2(&engine, url2);
QVERIFY2(c2.isReady(), qPrintable(c2.errorString()));
+ QTest::ignoreMessage(
+ QtCriticalMsg,
+ qPrintable(url2.toString() + u":36: 15 should be coerced to void because the function "
+ "called is insufficiently annotated. The original value "
+ "is retained. "
+ "This will change in a future version of Qt."_s));
+
QScopedPointer<QObject> enforced(c2.create());
QCOMPARE(enforced->property("l").toInt(), 2); // strlen("no")
- QCOMPARE(enforced->property("m").toInt(), 12);
+ QCOMPARE(enforced->property("m").toInt(), 77);
QCOMPARE(enforced->property("n").toInt(), 99);
QCOMPARE(enforced->property("o").toInt(), 77);
}