aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-02-16 15:08:20 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-02-21 14:27:54 +0100
commite2611e8ee948b32a627277bb9783ce8f35cc2d69 (patch)
tree90ad5f6083f1ebd1c9b9402cea7e6c4b3b53652f /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent49dc279bdcfb121089aabb86d6475e371a8f9430 (diff)
QmlCompiler: Fix conditions around as casts
We can only generate an as-cast from an optional value type if we know that the optional type is actually the requested one. Otherwise we have to reject for now. We might add more logic here in a further iteration, and process more complicated type assertions. However, we should pick such logic back to 6.6. Amends commit 05f56d7c78754855c643470ad4e8dfd35c96f927. Pick-to: 6.7 6.6 Change-Id: I37fc1b6018bfb0663e5ce4fd80084c7d13c6d3e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index ccaffbcd72..dc062ef55e 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -2123,7 +2123,6 @@ void tst_QmlCppCodegen::getOptionalLookup_data()
// Value Types
QTest::addRow("int on rect") << u"tv1"_s << QVariant(50);
QTest::addRow("int on point") << u"tv2"_s << QVariant(-10);
- QTest::addRow("int on variant as point") << u"tv3"_s << QVariant(5);
QTest::addRow("int on undefined as point") << u"tv4"_s << QVariant(); // undefined
// Enums
@@ -2135,12 +2134,8 @@ void tst_QmlCppCodegen::getOptionalLookup_data()
// Complex chains
QTest::addRow("mixed 1") << u"tc1"_s << QVariant(-10);
QTest::addRow("mixed 2") << u"tc2"_s << QVariant(0);
- QTest::addRow("mixed 3") << u"tc3"_s << QVariant(5);
QTest::addRow("early out 1") << u"tc4"_s << QVariant(); // undefined
QTest::addRow("early out 2") << u"tc5"_s << QVariant(); // undefined
- QTest::addRow("early out 3") << u"tc6"_s << QVariant(); // undefined
- QTest::addRow("complex2") << u"tc7"_s << QVariant(); // undefined
- QTest::addRow("complex3") << u"tc8"_s << QVariant(2);
}
void tst_QmlCppCodegen::getOptionalLookup()
@@ -4778,6 +4773,16 @@ void tst_QmlCppCodegen::valueTypeBehavior()
// If the binding throws an exception, the value doesn't change.
QCOMPARE(o->property("x"), 10);
+
+ QCOMPARE(o->property("tv3"), 5);
+ QCOMPARE(o->property("tc3"), 5);
+ QCOMPARE(o->property("tc6"), QVariant());
+ QCOMPARE(o->property("tc7"), QVariant());
+ QCOMPARE(o->property("tc8"), 2);
+
+ // The default greeting is never applied because undefined can be coerced to string
+ QCOMPARE(o->property("greeting1"), QLatin1String("undefined"));
+ QCOMPARE(o->property("greeting2"), QLatin1String("Custom Greeting"));
}
}