[vala/staging] girparser: Don't count instance-parameter when checking for backwards closure reference



commit f058e9e828f494ebf8d60cabff7999f219048623
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Mar 4 11:45:41 2022 +0100

    girparser: Don't count instance-parameter when checking for backwards closure reference
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/721

 .../delegate-closure-destroy-index-conflict.test   | 41 ++++++++++++++++++++++
 vala/valagirparser.vala                            |  6 ++--
 2 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/tests/gir/delegate-closure-destroy-index-conflict.test 
b/tests/gir/delegate-closure-destroy-index-conflict.test
index 4bf57bfa6..449136c90 100644
--- a/tests/gir/delegate-closure-destroy-index-conflict.test
+++ b/tests/gir/delegate-closure-destroy-index-conflict.test
@@ -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);
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 53d073926..355d0fa74 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -3469,11 +3469,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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]