From e0a9a4420324f18e9964372f6695eac920031dc9 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 4 Aug 2020 09:02:25 +0200 Subject: [PATCH] vala: Inherit CCode.returns_floating_reference attribute from base method Regression of 49a6d475052ec476140c545a26ac8d5abe35c849 Fixes https://gitlab.gnome.org/GNOME/vala/issues/1053 --- tests/Makefile.am | 1 + .../floating-reference-base-method.vala | 49 +++++++++++++++++++ vala/valamethod.vala | 9 ++++ 3 files changed, 59 insertions(+) create mode 100644 tests/semantic/floating-reference-base-method.vala diff --git a/tests/Makefile.am b/tests/Makefile.am index c5e400dd4..0e35fd799 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..d5151efa8 --- /dev/null +++ b/tests/semantic/floating-reference-base-method.vala @@ -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 (); +} diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 1084746cb..b2b2012aa 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -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; -- 2.47.2