[vala/0.48] codegen: Use correct target/destroy of delegate field initializer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] codegen: Use correct target/destroy of delegate field initializer
- Date: Thu, 17 Feb 2022 08:47:06 +0000 (UTC)
commit 8c86b4e5a124c0c913652ce76f244ea006037fce
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Jan 31 16:37:44 2022 +0100
codegen: Use correct target/destroy of delegate field initializer
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1285
codegen/valaccodebasemodule.vala | 15 ++++++++++++---
tests/Makefile.am | 1 +
tests/delegates/class-field-initializer.vala | 26 ++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 39abb0f41..94a31b3f5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1222,10 +1222,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var delegate_type = (DelegateType) f.variable_type;
if (delegate_type.delegate_symbol.has_target) {
var field_value = get_field_cvalue (f,
load_this_parameter ((TypeSymbol) f.parent_symbol));
-
- ccode.add_assignment (get_delegate_target_cvalue
(field_value), new CCodeIdentifier ("self"));
+ var target_cvalue = get_delegate_target_cvalue
(f.initializer.target_value);
+ if (target_cvalue != null) {
+ ccode.add_assignment
(get_delegate_target_cvalue (field_value), target_cvalue);
+ } else {
+ ccode.add_assignment
(get_delegate_target_cvalue (field_value), new CCodeIdentifier ("self"));
+ }
if (delegate_type.is_disposable ()) {
- ccode.add_assignment
(get_delegate_target_destroy_notify_cvalue (field_value), new CCodeConstant ("NULL"));
+ var destroy_cvalue =
get_delegate_target_destroy_notify_cvalue (f.initializer.target_value);
+ if (destroy_cvalue != null) {
+ ccode.add_assignment
(get_delegate_target_destroy_notify_cvalue (field_value), destroy_cvalue);
+ } else {
+ ccode.add_assignment
(get_delegate_target_destroy_notify_cvalue (field_value), new CCodeConstant ("NULL"));
+ }
}
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0dd5fc9d4..c36f4aad3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -405,6 +405,7 @@ TESTS = \
structs/bug777194.vala \
structs/bug777194-2.vala \
delegates/casting.vala \
+ delegates/class-field-initializer.vala \
delegates/compatible.vala \
delegates/delegate_only.vala \
delegates/delegate-recusive.vala \
diff --git a/tests/delegates/class-field-initializer.vala b/tests/delegates/class-field-initializer.vala
new file mode 100644
index 000000000..5a84e4af8
--- /dev/null
+++ b/tests/delegates/class-field-initializer.vala
@@ -0,0 +1,26 @@
+delegate string FooFunc ();
+
+FooFunc get_func () {
+ var s = "foo";
+ return () => { return s; };
+}
+
+class Foo {
+ public FooFunc func = get_func ();
+}
+
+[Compact]
+class Bar {
+ public FooFunc func = get_func ();
+}
+
+void main () {
+ {
+ var foo = new Foo ();
+ assert (foo.func () == "foo");
+ }
+ {
+ var bar = new Bar ();
+ assert (bar.func () == "foo");
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]