]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Don't count instance-parameter when checking for backwards closure reference
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 4 Mar 2022 10:45:41 +0000 (11:45 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 Mar 2022 08:06:43 +0000 (09:06 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/721

tests/gir/delegate-closure-destroy-index-conflict.test
vala/valagirparser.vala

index 4bf57bfa630402db22faf5277baf239584ddd8be..449136c905488832cd29dcd5c6f43e24e8071896 100644 (file)
@@ -2,6 +2,40 @@ GIR
 
 Input:
 
+<class name="Foo"
+       c:symbol-prefix="foo"
+       c:type="TestFoo"
+       parent="GLib.Object"
+       glib:type-name="TestFoo"
+       glib:get-type="test_foo_get_type"
+       glib:type-struct="FooClass">
+  <field name="parent">
+    <type name="GLib.Object" c:type="GObject"/>
+  </field>
+  <method name="function" c:identifier="test_function">
+    <return-value transfer-ownership="none">
+      <type name="none"/>
+    </return-value>
+    <parameters>
+      <instance-parameter name="self" transfer-ownership="none">
+        <type name="Test.Foo" c:type="TestFoo*"/>
+      </instance-parameter>
+      <parameter name="callback" transfer-ownership="none" allow-none="1" closure="1" scope="notified" destroy="2">
+        <type name="GLib.Func" c:type="GFunc"/>
+      </parameter>
+      <parameter name="callback_target" transfer-ownership="none" allow-none="1" closure="0">
+        <type name="gpointer" c:type="void*"/>
+      </parameter>
+      <parameter name="callback_target_destroy_notify" transfer-ownership="none" scope="call" destroy="0">
+        <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+      </parameter>
+    </parameters>
+  </method>
+</class>
+<record name="FooClass"
+        c:type="TestFooClass"
+        glib:is-gtype-struct-for="Foo">
+</record>
 <function name="function" c:identifier="test_function">
   <return-value transfer-ownership="none">
     <type name="none"/>
@@ -21,5 +55,12 @@ Input:
 
 Output:
 
+[CCode (cheader_filename = "test.h", type_id = "test_foo_get_type ()")]
+public class Foo : GLib.Object {
+       [CCode (has_construct_function = false)]
+       protected Foo ();
+       [CCode (cname = "test_function")]
+       public void function (owned GLib.Func? callback);
+}
 [CCode (cheader_filename = "test.h")]
 public static void function (owned GLib.Func? callback);
index 7657bd1a1b91330e98bed27885b96058972ab64d..1b8336293a1c5bc176877d42dcbb4e92720bba4f 100644 (file)
@@ -3439,11 +3439,13 @@ public class Vala.GirParser : CodeVisitor {
 
                        var current_parameter_idx = -1;
                        while (current_token == MarkupTokenType.START_ELEMENT) {
-                               current_parameter_idx++;
-
                                var is_instance_parameter = (reader.name == "instance-parameter"
                                        && !(symbol_type == "function" || symbol_type == "constructor"));
 
+                               if (!is_instance_parameter) {
+                                       current_parameter_idx++;
+                               }
+
                                if (instance_idx > -2 && instance_idx == current_parameter_idx) {
                                        skip_element ();
                                        continue;