aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-04-09 11:02:44 +0200
committerUlf Hermann <ulf.hermann@qt.io>2024-04-11 15:47:39 +0200
commit1087977a9a967dc4058eda7303ddd9f59874e21e (patch)
tree75c896ded22c423c7baf75389b24e8741d712596 /tests/auto/qml
parent6c99431170129c106cd8f0dd302b556642815a64 (diff)
QmlCompiler: Correctly mark side effects for list operations
The contents of a QQmlListProperty are mutable even if the property is not. This is because QQmlListProperty is only a view on a different container. Pick-to: 6.7 Fixes: QTBUG-123196 Change-Id: Id6309b1e1ddc219bf35e8d9888b8415dcc0f9d43 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/readonlyListProperty.qml17
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp12
3 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 45f12ca506..3311c5a4c1 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -228,6 +228,7 @@ set(qml_files
pressAndHoldButton.qml
reduceWithNullThis.qml
readEnumFromInstance.qml
+ readonlyListProperty.qml
registerPropagation.qml
registerelimination.qml
renameAdjust.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/readonlyListProperty.qml b/tests/auto/qml/qmlcppcodegen/data/readonlyListProperty.qml
new file mode 100644
index 0000000000..149638283b
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/readonlyListProperty.qml
@@ -0,0 +1,17 @@
+import QtQml
+
+QtObject {
+ id: testObj
+
+ // "readonly" means the identity of the list cannot be changed.
+ // Its contents can be changed.
+ readonly default property list<QtObject> theList
+
+ Component.onCompleted: {
+ for (var i = 0; i < 4; i++)
+ testObj.theList.push(testObj)
+ }
+
+ property int l: theList.length
+}
+
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 980ff1986b..fb1ab69c71 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -194,6 +194,7 @@ private slots:
void propertyOfParent();
void reduceWithNullThis();
void readEnumFromInstance();
+ void readonlyListProperty();
void registerElimination();
void registerPropagation();
void renameAdjust();
@@ -4025,6 +4026,17 @@ void tst_QmlCppCodegen::readEnumFromInstance()
QCOMPARE(result, 0);
}
+void tst_QmlCppCodegen::readonlyListProperty()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/readonlyListProperty.qml"_s));
+ QVERIFY2(component.isReady(), component.errorString().toUtf8());
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QCOMPARE(object->property("l").toInt(), 4);
+}
+
void tst_QmlCppCodegen::registerElimination()
{
QQmlEngine engine;