fix readonly metaproperties (revealed by compiler warning)
authorShawn Rutledge <shawn.rutledge@theqtcompany.com>
Mon, 20 Jul 2015 12:21:08 +0000 (14:21 +0200)
committerShawn Rutledge <shawn.rutledge@theqtcompany.com>
Tue, 21 Jul 2015 09:00:57 +0000 (09:00 +0000)
Found thanks to -Wparentheses + gcc 5.1

Change-Id: Iad784a26d268b85f7c67623fd63f0b097a9f29f9
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/compiler/qqmltypecompiler.cpp
tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml [new file with mode: 0644]
tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp

index 46b67d598385a6cd640e3eb485cc6a0b042acac0..4e9817aa0dab94b4aa06e28b2bab22b127c2579b 100644 (file)
@@ -836,7 +836,7 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
                 propertyFlags |= QQmlPropertyData::IsQList;
         }
 
-        if ((!p->flags & QV4::CompiledData::Property::IsReadOnly) && p->type != QV4::CompiledData::Property::CustomList)
+        if (!(p->flags & QV4::CompiledData::Property::IsReadOnly) && p->type != QV4::CompiledData::Property::CustomList)
             propertyFlags |= QQmlPropertyData::IsWritable;
 
 
@@ -860,7 +860,7 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
             continue;
 
         quint32 propertyFlags = QQmlPropertyData::IsVarProperty;
-        if (!p->flags & QV4::CompiledData::Property::IsReadOnly)
+        if (!(p->flags & QV4::CompiledData::Property::IsReadOnly))
             propertyFlags |= QQmlPropertyData::IsWritable;
 
         VMD *vmd = (QQmlVMEMetaData *)dynamicData.data();
diff --git a/tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml b/tests/auto/qml/qqmlproperty/data/readonlyPrimitiveVsVar.qml
new file mode 100644 (file)
index 0000000..253d61d
--- /dev/null
@@ -0,0 +1,8 @@
+import QtQuick 2.0
+
+QtObject {
+    readonly property var r_var: 1;
+    readonly property int r_int: 1;
+    property var w_var: 1;
+    property int w_int: 1;
+}
index c4b2325843d8d1c6704e251c270b9d653f366d52..a8b06ffa714b26fe72d9f728117a2f025ec0f8e6 100644 (file)
@@ -146,6 +146,7 @@ private slots:
     void warnOnInvalidBinding();
     void registeredCompositeTypeProperty();
     void deeplyNestedObject();
+    void readOnlyDynamicProperties();
 
     void copy();
 private:
@@ -2039,6 +2040,20 @@ void tst_qqmlproperty::deeplyNestedObject()
     QCOMPARE(p.read(), QVariant(14));
 }
 
+void tst_qqmlproperty::readOnlyDynamicProperties()
+{
+    QQmlComponent comp(&engine, testFileUrl("readonlyPrimitiveVsVar.qml"));
+    QObject *obj = comp.create();
+    QVERIFY(obj != 0);
+
+    QVERIFY(!obj->metaObject()->property(obj->metaObject()->indexOfProperty("r_var")).isWritable());
+    QVERIFY(!obj->metaObject()->property(obj->metaObject()->indexOfProperty("r_int")).isWritable());
+    QVERIFY(obj->metaObject()->property(obj->metaObject()->indexOfProperty("w_var")).isWritable());
+    QVERIFY(obj->metaObject()->property(obj->metaObject()->indexOfProperty("w_int")).isWritable());
+
+    delete obj;
+}
+
 void tst_qqmlproperty::initTestCase()
 {
     QQmlDataTest::initTestCase();