]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Inherit CCode.returns_floating_reference attribute from base method
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 4 Aug 2020 07:02:25 +0000 (09:02 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 4 Aug 2020 07:23:18 +0000 (09:23 +0200)
Regression of 49a6d475052ec476140c545a26ac8d5abe35c849

Fixes https://gitlab.gnome.org/GNOME/vala/issues/1053

tests/Makefile.am
tests/semantic/floating-reference-base-method.vala [new file with mode: 0644]
vala/valamethod.vala

index c604b28876886f30e862e5094524d05f50cd9e1d..02e093defac3730ac1e53afbf7e2d2505f7bb18a 100644 (file)
@@ -844,6 +844,7 @@ TESTS = \
        semantic/field-valist.test \
        semantic/field-void.test \
        semantic/floating-reference.vala \
+       semantic/floating-reference-base-method.vala \
        semantic/floating-reference-error.vala \
        semantic/foreach-iterator-args.test \
        semantic/foreach-iterator-element-owned.test \
diff --git a/tests/semantic/floating-reference-base-method.vala b/tests/semantic/floating-reference-base-method.vala
new file mode 100644 (file)
index 0000000..d5151ef
--- /dev/null
@@ -0,0 +1,49 @@
+interface IFoo {
+       [CCode (returns_floating_reference = true)]
+       public abstract InitiallyUnowned? foo ();
+}
+
+interface IBar {
+       [CCode (returns_floating_reference = true)]
+       public abstract InitiallyUnowned? bar ();
+}
+
+class Foo : IFoo, IBar {
+       [CCode (returns_floating_reference = true)]
+       public InitiallyUnowned? foo () {
+               return null;
+       }
+
+       public InitiallyUnowned? bar () {
+               return null;
+       }
+
+       [CCode (returns_floating_reference = true)]
+       public virtual InitiallyUnowned? faz () {
+               return null;
+       }
+
+       [CCode (returns_floating_reference = true)]
+       public virtual InitiallyUnowned? baz () {
+               return null;
+       }
+}
+
+class Manam : Foo {
+       [CCode (returns_floating_reference = true)]
+       public override InitiallyUnowned? faz () {
+               return null;
+       }
+
+       public override InitiallyUnowned? baz () {
+               return null;
+       }
+}
+
+void main () {
+       var manam = new Manam ();
+       manam.foo ();
+       manam.bar ();
+       manam.faz ();
+       manam.baz ();
+}
index ef8a48dae8dd8713445782d5e810b866c448eeb2..152f6b3bedfe9867a6d5c16580ceb6eec939962f 100644 (file)
@@ -366,6 +366,13 @@ public class Vala.Method : Subroutine, Callable {
                        }
                }
 
+               var return_type = this.return_type.copy ();
+               if (has_attribute_argument ("CCode", "returns_floating_reference")) {
+                       return_type.floating_reference = returns_floating_reference;
+               } else {
+                       return_type.floating_reference = base_method.returns_floating_reference;
+               }
+
                var actual_base_type = base_method.return_type.get_actual_type (object_type, method_type_args, node_reference);
                if (!return_type.equals (actual_base_type)) {
                        invalid_match = "Base method expected return type `%s', but `%s' was provided".printf (actual_base_type.to_prototype_string (), return_type.to_prototype_string ());
@@ -627,6 +634,7 @@ public class Vala.Method : Subroutine, Callable {
 
                                _base_method = base_method;
                                copy_attribute_double (base_method, "CCode", "instance_pos");
+                               copy_attribute_bool (base_method, "CCode", "returns_floating_reference");
                                return;
                        }
                }
@@ -686,6 +694,7 @@ public class Vala.Method : Subroutine, Callable {
                if (base_match != null) {
                        _base_interface_method = base_match;
                        copy_attribute_double (base_match, "CCode", "instance_pos");
+                       copy_attribute_bool (base_match, "CCode", "returns_floating_reference");
                        return;
                } else if (!hides && invalid_base_match != null) {
                        error = true;