]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Report warning if property-type is not compatible with GLib.Object
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 27 Mar 2017 12:07:23 +0000 (14:07 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 15 Sep 2017 12:57:52 +0000 (14:57 +0200)
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
tests/objects/bug764481.vala
tests/objects/properties.vala
tests/structs/bug606202.vala

index 8b3e7a2693455b5f51cc260d33ad8c6dfbe8ea4f..6c3496bc6bfa64d7bcbf543279963c8c47e70fa4 100644 (file)
@@ -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);
index 92c82c83a629a0401fa8b0be8a90d347525c0fd0..99f02a7d5893346416623b46f93460d1a0102aba 100644 (file)
@@ -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);
 }
index 2e2b2ee059cd5b1983c6927c1346ff913ff9db63..3035b99d84203e575717188fbf23fafb65037e29 100644 (file)
@@ -1,5 +1,6 @@
 using GLib;
 
+[CCode (has_target = false)]
 public delegate void Delegate ();
 
 public struct RealStruct {
index 78beb5b8d3bef60a3b4023d59ee6e8ce46c634eb..f26fc721c02e651002a3edd7359fea1c3c2fdc4c 100644 (file)
@@ -6,7 +6,7 @@ struct Foo {
        }
 }
 
-class Bar : Object {
+class Bar {
        public Foo? foo { get; set; }
 }