aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data
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/data
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/data')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/getOptionalLookup.qml14
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/valueTypeCast.qml36
2 files changed, 36 insertions, 14 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/getOptionalLookup.qml b/tests/auto/qml/qmlcppcodegen/data/getOptionalLookup.qml
index 5ba8bd51ef..ee360d7142 100644
--- a/tests/auto/qml/qmlcppcodegen/data/getOptionalLookup.qml
+++ b/tests/auto/qml/qmlcppcodegen/data/getOptionalLookup.qml
@@ -11,13 +11,6 @@ GOL_Object {
property var v: Qt.point(5, 5)
property var u: undefined
- function f(input: bool) : var {
- if (input)
- return 0
- return Qt.point(2, 2)
- }
-
-
property int to1: root?.i
property string to2: root?.s
property GOL_Object to3: root?.childA
@@ -27,8 +20,6 @@ GOL_Object {
property int tv1: root.r?.bottom
property int tv2: root.p?.y
- property int tv3: (root.v as point)?.x
- property var tv4: (root.u as rect)?.x
property int te1: root?.e
property int te2: GOL_Object?.V2
@@ -37,10 +28,7 @@ GOL_Object {
property int tc1: root?.p.y
property int tc2: root.r?.x
- property int tc3: (root?.v as point)?.y
+
property var tc4: root?.childA?.s
property var tc5: root.childA?.s
- property var tc6: (root?.u as rect)?.height
- property var tc7: (f(true) as point)?.x
- property var tc8: (f(false) as point)?.x
}
diff --git a/tests/auto/qml/qmlcppcodegen/data/valueTypeCast.qml b/tests/auto/qml/qmlcppcodegen/data/valueTypeCast.qml
index d1c9198cbd..a775773dda 100644
--- a/tests/auto/qml/qmlcppcodegen/data/valueTypeCast.qml
+++ b/tests/auto/qml/qmlcppcodegen/data/valueTypeCast.qml
@@ -1,9 +1,43 @@
-pragma Strict
pragma ValueTypeBehavior: Addressable
import QtQml
QtObject {
+ id: root
property rect r: Qt.rect(10, 20, 3, 4)
property var v: r
property real x: (v as rect).x
+
+ function f(input: bool) : var {
+ if (input)
+ return 0
+ return Qt.point(2, 2)
+ }
+
+ property var vv: Qt.point(5, 5)
+ property var uu: undefined
+
+ property int tv3: (root.vv as point)?.x
+ property var tv4: (root.uu as rect)?.x
+ property int tc3: (root?.vv as point)?.y
+ property var tc6: (root?.uu as rect)?.height
+ property var tc7: (f(true) as point)?.x
+ property var tc8: (f(false) as point)?.x
+
+ property string greeting1
+ property string greeting2
+
+ readonly property string defaultGreeting: "Default Greeting"
+ property QtObject o: QtObject {
+ id: o
+ property var customGreeting
+ function greet() : string {
+ return (o.customGreeting as string) ?? root.defaultGreeting
+ }
+ }
+
+ Component.onCompleted: {
+ root.greeting1 = o.greet()
+ o.customGreeting = "Custom Greeting"
+ root.greeting2 = o.greet()
+ }
}