aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2023-10-04 12:56:52 +0200
committerUlf Hermann <[email protected]>2023-10-19 09:30:27 +0200
commit742fba7d7a60de1f81c15d442e510946abaaefcf (patch)
tree0d632268dc5c87a81b97592fa7075bd31ef5b4cf
parentbf2258e6f44f1279eee5e9c2dd595c5dd2020784 (diff)
QmlCompiler: Comment about not allowing modifications to return values
This trap is all too easy to forget about. Let's make sure the next person thinking about it understands it. Change-Id: Ib7bd566e1d8c4264a99ae59e79384c4e87581d43 Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index c2aaeeec77..355b261241 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -1010,6 +1010,15 @@ void QQmlJSCodeGenerator::generateWriteBack(int registerIndex)
const int lookupIndex = writeBack.resultLookupIndex();
if (lookupIndex == -1) {
+ // This is essential for the soundness of the type system.
+ //
+ // If a value or a list is returned from a function, we cannot know
+ // whether it is a copy or a reference. Therefore, we cannot know whether
+ // we have to write it back and so we have to reject any write on it.
+ //
+ // Only if we are sure that the value is locally created we can be sure
+ // we don't have to write it back. In this latter case we could allow
+ // a modification that doesn't write back.
reject(u"write-back of non-lookup"_s);
break;
}