From 9eb6240ebd0b7f52ec49aba757a8c355b25203e0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 21 Jun 2023 14:11:41 +0200 Subject: 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 --- tests/auto/qml/qqmllanguage/data/signatureEnforced.qml | 5 ++++- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'tests/auto') 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 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); } -- cgit v1.2.3