]> 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>
Mon, 10 Aug 2020 08:00:16 +0000 (10:00 +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 c5e400dd4c5dd87f41d0c5374ba57cb1802dea44..0e35fd7996091379284c2a37a283d937f30de7c6 100644 (file)
@@ -800,6 +800,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 1084746cb254f73d1603a3c2e26df276ea0c237a..b2b2012aa2fdd382a64a0a7cf9b29314d36397fd 100644 (file)
@@ -364,6 +364,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 ());
@@ -625,6 +632,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;
                        }
                }
@@ -684,6 +692,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;