[vala/staging: 6/6] codegen: Report error if property-type is not compatible with GLib.Object
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 6/6] codegen: Report error if property-type is not compatible with GLib.Object
- Date: Fri, 14 Jul 2017 15:18:33 +0000 (UTC)
commit 2f032c9aa3a28be25b599b3aca1464a0cd32a904
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Mar 27 14:07:23 2017 +0200
codegen: Report error 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 an error instead of not registering it silently.
https://bugzilla.gnome.org/show_bug.cgi?id=693932
codegen/valagobjectmodule.vala | 45 +++++++++++++++++++++++++--------------
tests/Makefile.am | 1 +
tests/objects/bug693932.test | 8 +++++++
tests/objects/bug764481.vala | 20 -----------------
tests/objects/properties.vala | 1 +
tests/structs/bug606202.vala | 2 +-
6 files changed, 40 insertions(+), 37 deletions(-)
---
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 53afb28..fb38739 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.error (prop.source_reference, "Type `%s' can not be used for a
GLib.Object property".printf (prop.property_type.to_qualified_string ()));
+ }
continue;
}
@@ -723,22 +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;
- }
-
- var en = prop.property_type.data_type as Enum;
- if (en != null && (!get_ccode_has_type_id (en) || 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;
}
@@ -766,6 +754,31 @@ public class Vala.GObjectModule : GTypeModule {
return true;
}
+ bool has_valid_gobject_property_type (Property prop) {
+ var prop_type = prop.property_type;
+
+ var st = prop_type.data_type as Struct;
+ if (st != null && (!get_ccode_has_type_id (st) || prop_type.nullable)) {
+ return false;
+ }
+
+ var en = prop_type.data_type as Enum;
+ if (en != null && (!get_ccode_has_type_id (en) || prop_type.nullable)) {
+ return false;
+ }
+
+ if (prop_type is ArrayType && ((ArrayType) prop_type).element_type.data_type !=
string_type.data_type) {
+ return false;
+ }
+
+ var d = prop_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/Makefile.am b/tests/Makefile.am
index 1153c37..76d3965 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -211,6 +211,7 @@ TESTS = \
objects/bug667668.vala \
objects/bug681356.vala \
objects/bug683646.vala \
+ objects/bug693932.test \
objects/bug695671.vala \
objects/bug701978.vala \
objects/bug702736.vala \
diff --git a/tests/objects/bug693932.test b/tests/objects/bug693932.test
new file mode 100644
index 0000000..e521eca
--- /dev/null
+++ b/tests/objects/bug693932.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+class Foo : Object {
+ public int16 prop { get; set;}
+}
+
+void main () {
+}
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]