]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't allow assigning GtkChild fields/properties
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 16 Jan 2021 16:11:14 +0000 (17:11 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 17 Jan 2021 12:11:08 +0000 (13:11 +0100)
These are handled exclusively by GtkBuilder

See https://gitlab.gnome.org/GNOME/vala/issues/1121

tests/Makefile.am
tests/gtktemplate/gtkchild-field-assignment.test [new file with mode: 0644]
tests/gtktemplate/gtkchild-field-out-assignment.test [new file with mode: 0644]
tests/gtktemplate/gtkchild-field-ref-assignment.test [new file with mode: 0644]
tests/gtktemplate/gtkchild-property-assignment.test [new file with mode: 0644]
tests/gtktemplate/gtktemplate.vala
tests/gtktemplate/tests-extra-environment.sh [new file with mode: 0644]
vala/valaassignment.vala
vala/valaproperty.vala
vala/valaunaryexpression.vala

index bca7145211c86ffb55019c7afa7b01a2bfd702a7..8c001a0994bd43d6d929aeeed10db5c42d880d13 100644 (file)
@@ -709,6 +709,10 @@ TESTS = \
        gir/property-non-readable.test \
        gir/symbol-type-csuffix.test \
        gir/union.test \
+       gtktemplate/gtkchild-field-assignment.test \
+       gtktemplate/gtkchild-field-out-assignment.test \
+       gtktemplate/gtkchild-field-ref-assignment.test \
+       gtktemplate/gtkchild-property-assignment.test \
        annotations/deprecated.vala \
        annotations/description.vala \
        annotations/noaccessormethod.test \
@@ -1152,6 +1156,7 @@ LINUX_TESTS += \
 endif
 
 EXTRA_DIST = \
+       gtktemplate/tests-extra-environment.sh \
        linux/tests-extra-environment.sh \
        nullability/tests-extra-environment.sh \
        posix/tests-extra-environment.sh \
diff --git a/tests/gtktemplate/gtkchild-field-assignment.test b/tests/gtktemplate/gtkchild-field-assignment.test
new file mode 100644 (file)
index 0000000..4fc71f1
--- /dev/null
@@ -0,0 +1,14 @@
+Invalid Code
+
+[GtkTemplate (ui = "/org/example/gtktemplate.ui")]
+public class GtkTemplate : Gtk.ApplicationWindow {
+       [GtkChild]
+       public unowned Gtk.Button button0;
+
+       void foo () {
+               button0 = new Gtk.Button ();
+       }
+}
+
+void main () {
+}
diff --git a/tests/gtktemplate/gtkchild-field-out-assignment.test b/tests/gtktemplate/gtkchild-field-out-assignment.test
new file mode 100644 (file)
index 0000000..3f82f42
--- /dev/null
@@ -0,0 +1,17 @@
+Invalid Code
+
+[GtkTemplate (ui = "/org/example/gtktemplate.ui")]
+public class GtkTemplate : Gtk.ApplicationWindow {
+       [GtkChild]
+       public unowned Gtk.Button button0;
+
+       void foo () {
+               bar (out button0);
+       }
+
+       void bar (out unowned Gtk.Button b) {
+       }
+}
+
+void main () {
+}
diff --git a/tests/gtktemplate/gtkchild-field-ref-assignment.test b/tests/gtktemplate/gtkchild-field-ref-assignment.test
new file mode 100644 (file)
index 0000000..e8dab2e
--- /dev/null
@@ -0,0 +1,17 @@
+Invalid Code
+
+[GtkTemplate (ui = "/org/example/gtktemplate.ui")]
+public class GtkTemplate : Gtk.ApplicationWindow {
+       [GtkChild]
+       public unowned Gtk.Button button0;
+
+       void foo () {
+               bar (ref button0);
+       }
+
+       void bar (ref unowned Gtk.Button b) {
+       }
+}
+
+void main () {
+}
diff --git a/tests/gtktemplate/gtkchild-property-assignment.test b/tests/gtktemplate/gtkchild-property-assignment.test
new file mode 100644 (file)
index 0000000..4905ea8
--- /dev/null
@@ -0,0 +1,14 @@
+Invalid Code
+
+[GtkTemplate (ui = "/org/example/gtktemplate.ui")]
+public class GtkTemplate : Gtk.ApplicationWindow {
+       [GtkChild]
+       public unowned Gtk.Button button0 { get; set; }
+
+       void foo () {
+               button0 = new Gtk.Button ();
+       }
+}
+
+void main () {
+}
index 5f66ccc219869c1863d51ec17c8e177e61769d15..3919680e26f540a137d30a4411284c9853ec6326 100644 (file)
@@ -1,7 +1,7 @@
 [GtkTemplate (ui = "/org/example/gtktemplate.ui")]
 public class GtkTemplate : Gtk.ApplicationWindow {
        [GtkChild]
-       public Gtk.Button button0 { get; set; }
+       public Gtk.Button button0 { get; }
 
        [GtkChild (internal = true)]
        public Gtk.Button button1;
diff --git a/tests/gtktemplate/tests-extra-environment.sh b/tests/gtktemplate/tests-extra-environment.sh
new file mode 100644 (file)
index 0000000..6c805e6
--- /dev/null
@@ -0,0 +1,2 @@
+PACKAGES="gtk+-3.0"
+VALAFLAGS="--gresources ${abs_srcdir}/gtktemplate/gtktemplate.gresource.xml"
index 79090ad9b76827dc6a51a94508127c48d049192f..4ffc75735b5ef11a2feb67ef63848b0abc690ca4 100644 (file)
@@ -178,6 +178,12 @@ public class Vala.Assignment : Expression {
                                return false;
                        }
 
+                       if (ma.symbol_reference.get_attribute ("GtkChild") != null) {
+                               error = true;
+                               Report.error (source_reference, "Assignment of [GtkChild] `%s' is not allowed", ma.symbol_reference.get_full_name ());
+                               return false;
+                       }
+
                        if (ma.symbol_reference is DynamicProperty) {
                                // target_type not available for dynamic properties
                        } else {
index 2fc1b4d603e6dd5cc03d0824e8537fba7170a576..0a2e437d596cec0984a3688b7cb023c465814e62 100644 (file)
@@ -492,6 +492,9 @@ public class Vala.Property : Symbol, Lockable {
                        get_accessor.check (context);
                }
                if (set_accessor != null) {
+                       if (get_attribute ("GtkChild") != null) {
+                               Report.warning (set_accessor.source_reference, "[GtkChild] property `%s' is not allowed to have `set' accessor", get_full_name ());
+                       }
                        set_accessor.check (context);
                }
 
index 76c31cd7aba254913cf427b2bf200cbdf594e1da..4bf6d4bc4a3c4337e9ea39e0de3c0198ece54f92 100644 (file)
@@ -229,6 +229,11 @@ public class Vala.UnaryExpression : Expression {
                                Report.error (source_reference, "ref and out method arguments can only be used with fields, parameters, local variables, and array element access");
                                return false;
                        }
+                       if (inner.symbol_reference.get_attribute ("GtkChild") != null) {
+                               error = true;
+                               Report.error (source_reference, "Assignment of [GtkChild] `%s' is not allowed", inner.symbol_reference.get_full_name ());
+                               return false;
+                       }
                        break;
                default:
                        error = true;