aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-01-25 11:18:17 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-02-05 14:32:16 +0100
commit6872342167acf2a20cb15ddf65d04b4e998ca286 (patch)
treedcc51bfefa0af797de5b7a7535dec702bbc3dc60 /src/qmlcompiler
parent2658ce482935ebdc5824a8295967de9ec3053902 (diff)
QmlCompiler: Prohibit non-resettable undefined assignment
If you assign undefined to a property that cannot hold undefined an exception should be generated. We cannot handle this, yet. Therefore we prohibit such assignments. Pick-to: 6.2 Change-Id: I0a034032f4522f017b452690d93319eb4bfedb1c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit afbf7b699061a38b27c91d3c95890dcc1f92ebe9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit ed50111eebec23d81e159026c8896c5d681c1e1e) (cherry picked from commit 1b0a03639c5bdaddd82b378ce77a21a28e82cbc7)
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index afae572d68..3464cd058d 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -943,11 +943,13 @@ void QQmlJSTypePropagator::generate_StoreProperty(int nameIndex, int base)
getCurrentSourceLocation());
}
- if (!property.property().reset().isEmpty()
+ if (!m_typeResolver->canHoldUndefined(property)
&& m_typeResolver->canHoldUndefined(m_state.accumulatorIn())) {
- // If the property is resettable we must not coerce the input to the property type
- // as that might eliminate an undefined value. For example, undefined -> string
- // becomes "undefined".
+ // If the input can be undefined but the property cannot hold it
+ // we must not coerce the input to the property type:
+ // * In the case of resettable properties this would suppress a reset
+ // * In the case of non-resettable properties it would suppress an exception.
+ // For example, undefined -> string becomes "undefined".
setError(u"Cannot assign potential undefined to %1"_s.arg(property.descriptiveName()));
}