aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4runtime.cpp
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2024-05-27 12:30:16 +0200
committerUlf Hermann <[email protected]>2024-05-28 11:58:35 +0200
commitad22f5f4996f31433b5c75b518431e668ca9707a (patch)
treeb72de7863264d6c74d0823c12c14c3a2089e24ca /src/qml/jsruntime/qv4runtime.cpp
parente43f871258ec6e7121d2baadf1968329fc628845 (diff)
QtQml: Restore as-casting of incompatible type to value type
This used to (mistakenly) return null, which is much better than constructing the value type. Amends commit 71e259837967f1eee50c057229094c2a971a1a61. Change-Id: I3da9d0a765d118dc8d85d7c5dde91936855bbf67 Reviewed-by: Fabian Kosmale <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4runtime.cpp')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 184e7c7819..5977360080 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -390,11 +390,28 @@ QV4::ReturnedValue Runtime::As::call(ExecutionEngine *engine, const Value &lval,
if (!typeWrapper)
return Encode::undefined();
+ const auto *stackFrame = engine->currentStackFrame;
+ if (lval.as<QQmlValueTypeWrapper>()) {
+ qCWarning(lcCoercingTypeAssertion).nospace().noquote()
+ << stackFrame->source() << ':' << stackFrame->lineNumber() << ':'
+ << " Coercing between incompatible value types mistakenly yields null rather than"
+ << " undefined. Add 'pragma ValueTypeBehavior: Assertable' to prevent this.";
+ return Encode::null();
+ }
+
+ if (lval.as<QV4::QObjectWrapper>()) {
+ qCWarning(lcCoercingTypeAssertion).nospace().noquote()
+ << stackFrame->source() << ':' << stackFrame->lineNumber() << ':'
+ << " Coercing from instances of object types to value types mistakenly yields null"
+ << " rather than undefined. Add 'pragma ValueTypeBehavior: Assertable' to prevent"
+ << " this.";
+ return Encode::null();
+ }
+
result = coerce(engine, lval, typeWrapper->d()->type(), false);
if (result->isUndefined())
return Encode::undefined();
- const auto *stackFrame = engine->currentStackFrame;
qCWarning(lcCoercingTypeAssertion).nospace().noquote()
<< stackFrame->source() << ':' << stackFrame->lineNumber() << ':'
<< " Coercing a value to " << typeWrapper->toQStringNoThrow()