aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qqmltypecompiler.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-10 20:55:20 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-17 08:49:01 +0100
commit9aaf693e40616943c64c4c60637251bd2e940e69 (patch)
treedcd980ec842af4d74aa5d12213da4d1be946f9f5 /src/qml/compiler/qqmltypecompiler.cpp
parent43b7788b395b663f64d50652d46a2ac434b0d7c6 (diff)
[new compiler] Implement compile time error handling for lists
Change-Id: Ic26e8a01995c296ab9cd4deb8714a5cf17cfdf2b Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qqmltypecompiler.cpp')
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index dae57fe6f4..ce755d1c24 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -1564,6 +1564,11 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD
bool QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *propertyCache, QQmlPropertyData *property, const QV4::CompiledData::Binding *binding)
{
+ if (property->isQList()) {
+ recordError(binding->valueLocation, tr("Cannot assign primitives to lists"));
+ return false;
+ }
+
if (property->isEnum()) {
if (binding->flags & QV4::CompiledData::Binding::IsResolvedEnum)
return true;
@@ -1829,6 +1834,22 @@ bool QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *propertyCa
return true;
}
+/*!
+ Returns true if from can be assigned to a (QObject) property of type
+ to.
+*/
+bool QQmlPropertyValidator::canCoerce(int to, QQmlPropertyCache *fromMo)
+{
+ QQmlPropertyCache *toMo = enginePrivate->rawPropertyCacheForType(to);
+
+ while (fromMo) {
+ if (fromMo == toMo)
+ return true;
+ fromMo = fromMo->parent();
+ }
+ return false;
+}
+
bool QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *property, const QString &propertyName, const QV4::CompiledData::Binding *binding)
{
if (binding->flags & QV4::CompiledData::Binding::IsOnAssignment) {
@@ -1873,7 +1894,14 @@ bool QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *property, co
// We can convert everything to QVariant :)
return true;
} else if (property->isQList()) {
- // ### TODO: list error handling
+ const int listType = enginePrivate->listType(property->propType);
+ if (!QQmlMetaType::isInterface(listType)) {
+ QQmlPropertyCache *source = propertyCaches.value(binding->value.objectIndex);
+ if (!canCoerce(listType, source)) {
+ recordError(binding->valueLocation, tr("Cannot assign object to list"));
+ return false;
+ }
+ }
return true;
} else if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerObject && property->isFunction()) {
return true;