From 409807a022f65af86413ae09b5befff1eb99e727 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 2 Sep 2019 10:49:32 +0200 Subject: Make QQmlValueTypeFactory::valueType() and isValueType() consistent If isValueType() returns true, we should really return a non-null value from valueType(). Otherwise the assumption that QQmlValueTypeWrapper::valueType is never null breaks. In particular, the unknown type and various primitive types are _not_ value types. We special case the, probably common, UnknownType and check the actual return value of valueType() for anything else. In order to avoid looking up the metaobject each time we request a type that is not a value type, we keep an invalid value type as marker for "not checked yet" and replace that with nullptr once we determine that the type in question is indeed not a value type. Fixes: QTBUG-76866 Change-Id: I797f4cdd4db48ffc1b8fa2d919afc8022f67fa94 Reviewed-by: Simon Hausmann (cherry picked from commit f862b3edeb8a96a49a5d12620506d33d5a5aadca) Reviewed-by: Fabian Kosmale --- tests/auto/qml/qqmllanguage/data/fakeDotProperty.errors.txt | 2 +- .../qml/qqmllanguage/data/invalidGroupedProperty.2.errors.txt | 2 +- .../qml/qqmllanguage/data/objectValueTypeProperty.errors.txt | 2 +- tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 11 +++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/qqmllanguage/data/fakeDotProperty.errors.txt b/tests/auto/qml/qqmllanguage/data/fakeDotProperty.errors.txt index 30748234bc..5a144f2db5 100644 --- a/tests/auto/qml/qqmllanguage/data/fakeDotProperty.errors.txt +++ b/tests/auto/qml/qqmllanguage/data/fakeDotProperty.errors.txt @@ -1 +1 @@ -3:5:Invalid grouped property access +3:5:Invalid grouped property access: Property "value" with primitive type "int". diff --git a/tests/auto/qml/qqmllanguage/data/invalidGroupedProperty.2.errors.txt b/tests/auto/qml/qqmllanguage/data/invalidGroupedProperty.2.errors.txt index 810fd31b41..5deec4ccf9 100644 --- a/tests/auto/qml/qqmllanguage/data/invalidGroupedProperty.2.errors.txt +++ b/tests/auto/qml/qqmllanguage/data/invalidGroupedProperty.2.errors.txt @@ -1 +1 @@ -5:5:Invalid grouped property access +5:5:Invalid grouped property access: Property "o" with primitive type "int". diff --git a/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt b/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt index cefd62f9d4..043f714636 100644 --- a/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt +++ b/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt @@ -1 +1 @@ -4:18:Unexpected object assignment for property "x" +4:18:Can not assign value of type "MyTypeObject" to property "x", expecting "int" diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 41fa87d848..1426d4c583 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -96,6 +96,7 @@ private slots: void enumerableProperties(); void enumProperties(); void scarceTypes(); + void nonValueTypes(); private: QQmlEngine engine; @@ -1789,6 +1790,16 @@ void tst_qqmlvaluetypes::scarceTypes() QCOMPARE(QByteArray(pixmapValue->vtable()->className), QByteArray("VariantObject")); } +#define CHECK_TYPE_IS_NOT_VALUETYPE(Type, typeId, cppType) \ + QVERIFY(!QQmlValueTypeFactory::isValueType(QMetaType::Type)); + +void tst_qqmlvaluetypes::nonValueTypes() +{ + CHECK_TYPE_IS_NOT_VALUETYPE(UnknownType, 0, void) + QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(CHECK_TYPE_IS_NOT_VALUETYPE); +} + +#undef CHECK_TYPE_IS_NOT_VALUETYPE QTEST_MAIN(tst_qqmlvaluetypes) -- cgit v1.2.3