]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Apply G_PARAM_EXPLICIT_NOTIFY on properties with "notify = false"
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 31 Mar 2018 19:45:03 +0000 (21:45 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 1 Apr 2018 11:32:26 +0000 (13:32 +0200)
This requires --target-glib=2.42 to be passed.

codegen/valagtypemodule.vala
tests/Makefile.am
tests/objects/property-notify.vala [new file with mode: 0644]

index 3e553ec7e5d44490ff9b900abf473d952396d069..93f11da288055b059421cefae30c76d347527ea1 100644 (file)
@@ -2016,6 +2016,9 @@ public class Vala.GTypeModule : GErrorModule {
                                }
                        }
                }
+               if (context.require_glib_version (2, 42) && !prop.notify) {
+                       pflags = "%s%s".printf (pflags, " | G_PARAM_EXPLICIT_NOTIFY");
+               }
                if (prop.version.deprecated) {
                        pflags = "%s%s".printf (pflags, " | G_PARAM_DEPRECATED");
                }
index d4e4906dfedb9c11c7e3568a41962bd9f87873ba..0645f2f13b83c87a909a51fc0683645b5367644a 100644 (file)
@@ -235,6 +235,7 @@ TESTS = \
        objects/methods.vala \
        objects/paramspec.vala \
        objects/properties.vala \
+       objects/property-notify.vala \
        objects/regex.vala \
        objects/signals.vala \
        objects/signals-delegate.vala \
diff --git a/tests/objects/property-notify.vala b/tests/objects/property-notify.vala
new file mode 100644 (file)
index 0000000..d2e02b2
--- /dev/null
@@ -0,0 +1,36 @@
+class Foo : Object {
+       [CCode (notify = false)]
+       public string foo { get; set; }
+
+       public string bar { get; set; }
+
+       public string manam { get; set; }
+}
+
+void fail () {
+       assert_not_reached ();
+}
+
+int counter;
+void count () {
+       counter++;
+}
+
+void main () {
+       var foo = new Foo ();
+
+       foo.notify["foo"].connect (fail);
+       //FIXME Requires --target-glib=2.42 for G_PARAM_EXPLICIT_NOTIFY to be actually added
+       //foo.set_property ("foo", "foo");
+       foo.foo = "foo";
+
+       counter = 0;
+       foo.notify["bar"].connect (count);
+       foo.bar = "bar";
+       assert (counter == 1);
+
+       counter = 0;
+       foo.notify["manam"].connect (count);
+       foo.set_property ("manam", "manam");
+       assert (counter == 1);
+}