From dbbb514a084440c05d17e44c7992726d94b26750 Mon Sep 17 00:00:00 2001 From: Ulf Hermann <ulf.hermann@digia.com> Date: Tue, 21 Oct 2014 13:53:43 +0200 Subject: [PATCH] Check list property before component when validating bindings There are lists that won't accept a component as element. For example QQuickItem's children will only accept QQuickItems. Task-number: QTBUG-41848 Change-Id: I0fc7b0d1a4770d596caf681be92dff216f48d32b Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> --- src/qml/compiler/qqmltypecompiler.cpp | 4 ++-- .../auto/qml/qqmllanguage/data/badListItemType.errors.txt | 1 + tests/auto/qml/qqmllanguage/data/badListItemType.qml | 5 +++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/auto/qml/qqmllanguage/data/badListItemType.errors.txt create mode 100644 tests/auto/qml/qqmllanguage/data/badListItemType.qml diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 6a97386767..3a27a859fd 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -2334,8 +2334,6 @@ bool QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *property, co return true; } - if (isComponent(binding->value.objectIndex)) - return true; if (QQmlMetaType::isInterface(property->propType)) { // Can only check at instantiation time if the created sub-object successfully casts to the @@ -2354,6 +2352,8 @@ bool QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *property, co } } return true; + } else if (isComponent(binding->value.objectIndex)) { + return true; } else if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerObject && property->isFunction()) { return true; } else if (QQmlValueTypeFactory::isValueType(property->propType)) { diff --git a/tests/auto/qml/qqmllanguage/data/badListItemType.errors.txt b/tests/auto/qml/qqmllanguage/data/badListItemType.errors.txt new file mode 100644 index 0000000000..76809dc9a1 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/badListItemType.errors.txt @@ -0,0 +1 @@ +4:15:Cannot assign object to list diff --git a/tests/auto/qml/qqmllanguage/data/badListItemType.qml b/tests/auto/qml/qqmllanguage/data/badListItemType.qml new file mode 100644 index 0000000000..d612bb47b9 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/badListItemType.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + children: Component { Item {} } // QTBUG-41848 +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index d6d2911285..ec3e38dd14 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -118,6 +118,7 @@ private slots: void dynamicProperties(); void dynamicPropertiesNested(); void listProperties(); + void badListItemType(); void dynamicObjectProperties(); void dynamicSignalsAndSlots(); void simpleBindings(); @@ -1332,6 +1333,13 @@ void tst_qqmllanguage::listProperties() QCOMPARE(object->property("test").toInt(), 2); } +void tst_qqmllanguage::badListItemType() +{ + QQmlComponent component(&engine, testFileUrl("badListItemType.qml")); + QVERIFY(component.isError()); + VERIFY_ERRORS("badListItemType.errors.txt"); +} + // Tests the creation and assignment of dynamic object properties // ### Not complete void tst_qqmllanguage::dynamicObjectProperties() -- GitLab