[vala/db8c411392f89cf8fc0268d4819f15755d0c4137: 2/9] codegen: Report warning if property-type is not compatible with GLib.Object



commit 6aa600c11b0dc1bf15f217e0234d3c7eefb38032
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Mar 27 14:07:23 2017 +0200

    codegen: Report warning if property-type is not compatible with GLib.Object
    
    Not all types are supported to be used for "real" Object-properties.
    Therefore start to report a warning instead of not registering it silently.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693932

 codegen/valagobjectmodule.vala |   33 ++++++++++++++++++++++-----------
 tests/objects/bug764481.vala   |   20 --------------------
 tests/objects/properties.vala  |    1 +
 tests/structs/bug606202.vala   |    2 +-
 4 files changed, 24 insertions(+), 32 deletions(-)
---
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 8b3e7a2..6c3496b 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -135,6 +135,9 @@ public class Vala.GObjectModule : GTypeModule {
                var props = cl.get_properties ();
                foreach (Property prop in props) {
                        if (!is_gobject_property (prop)) {
+                               if (!has_valid_gobject_property_type (prop)) {
+                                       Report.warning (prop.source_reference, "Type `%s' can not be used for 
a GLib.Object property".printf (prop.property_type.to_qualified_string ()));
+                               }
                                continue;
                        }
 
@@ -723,17 +726,7 @@ public class Vala.GObjectModule : GTypeModule {
                        return false;
                }
 
-               var st = prop.property_type.data_type as Struct;
-               if (st != null && (!get_ccode_has_type_id (st) || prop.property_type.nullable)) {
-                       return false;
-               }
-
-               if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type 
!= string_type.data_type) {
-                       return false;
-               }
-
-               var d = prop.property_type as DelegateType;
-               if (d != null && d.delegate_symbol.has_target) {
+               if (!has_valid_gobject_property_type (prop)) {
                        return false;
                }
 
@@ -761,6 +754,24 @@ public class Vala.GObjectModule : GTypeModule {
                return true;
        }
 
+       bool has_valid_gobject_property_type (Property prop) {
+               var st = prop.property_type.data_type as Struct;
+               if (st != null && (!get_ccode_has_type_id (st) || prop.property_type.nullable)) {
+                       return false;
+               }
+
+               if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type 
!= string_type.data_type) {
+                       return false;
+               }
+
+               var d = prop.property_type as DelegateType;
+               if (d != null && d.delegate_symbol.has_target) {
+                       return false;
+               }
+
+               return true;
+       }
+
        public override void visit_method_call (MethodCall expr) {
                if (expr.call is MemberAccess) {
                        push_line (expr.source_reference);
diff --git a/tests/objects/bug764481.vala b/tests/objects/bug764481.vala
index 92c82c8..99f02a7 100644
--- a/tests/objects/bug764481.vala
+++ b/tests/objects/bug764481.vala
@@ -1,21 +1,13 @@
-[SimpleType]
-[CCode (has_type_id = false)]
-struct Minim {
-    int a;
-}
-
 struct Manam {
     int a;
 }
 
 class BaseFoo : Object {
     public virtual Manam st { get; set; }
-    public virtual Minim sst { get; set; }
 }
 
 class Foo : Object {
     public virtual Manam st { get; set; }
-    public virtual Minim sst { get; set; }
 }
 
 class Bar : Foo {
@@ -23,10 +15,6 @@ class Bar : Foo {
         get { return base.st; }
         set { base.st = value; }
     }
-    public override Minim sst {
-        get { return base.sst; }
-        set { base.sst = value; }
-    }
 }
 
 class Baz : BaseFoo {
@@ -34,22 +22,14 @@ class Baz : BaseFoo {
         get { return base.st; }
         set { base.st = value; }
     }
-    public override Minim sst {
-        get { return base.sst; }
-        set { base.sst = value; }
-    }
 }
 
 void main () {
     var bar = new Bar ();
     bar.st = { 42 };
-    bar.sst = { 42 };
     assert (bar.st.a == 42);
-    assert (bar.sst.a == 42);
 
     var baz = new Baz ();
     baz.st = { 23 };
-    baz.sst = { 23 };
     assert (baz.st.a == 23);
-    assert (baz.sst.a == 23);
 }
diff --git a/tests/objects/properties.vala b/tests/objects/properties.vala
index 2e2b2ee..3035b99 100644
--- a/tests/objects/properties.vala
+++ b/tests/objects/properties.vala
@@ -1,5 +1,6 @@
 using GLib;
 
+[CCode (has_target = false)]
 public delegate void Delegate ();
 
 public struct RealStruct {
diff --git a/tests/structs/bug606202.vala b/tests/structs/bug606202.vala
index 78beb5b..f26fc72 100644
--- a/tests/structs/bug606202.vala
+++ b/tests/structs/bug606202.vala
@@ -6,7 +6,7 @@ struct Foo {
        }
 }
 
-class Bar : Object {
+class Bar {
        public Foo? foo { get; set; }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]