From: Rico Tzschichholz Date: Mon, 27 Mar 2017 12:07:23 +0000 (+0200) Subject: codegen: Report warning if property-type is not compatible with GLib.Object X-Git-Tag: 0.39.1~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6aa600c11b0dc1bf15f217e0234d3c7eefb38032;p=thirdparty%2Fvala.git 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 --- diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala index 8b3e7a269..6c3496bc6 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 92c82c83a..99f02a7d5 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 2e2b2ee05..3035b99d8 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 78beb5b8d..f26fc721c 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; } }