[vala/0.34] codegen: Fix delegate initializer for instance fields



commit 5c9c24c43986a4804622f531b1d57fca90f44931
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Mar 22 16:04:00 2017 +0100

    codegen: Fix delegate initializer for instance fields
    
    Set delegate-target to "self" which is available in *_instance_init().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683925

 codegen/valaccodebasemodule.vala |   10 ++++++++++
 tests/Makefile.am                |    1 +
 tests/delegates/bug683925.vala   |   24 ++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ae2a8e8..0d5551c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1137,6 +1137,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                        var rhs_array_len = get_array_length_cvalue 
(field_value, 1);
                                                        ccode.add_assignment (lhs_array_size, rhs_array_len);
                                                }
+                                       } else if (f.variable_type is DelegateType) {
+                                               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"));
+                                                       if (delegate_type.is_disposable ()) {
+                                                               ccode.add_assignment 
(get_delegate_target_destroy_notify_cvalue (field_value), new CCodeIdentifier ("NULL"));
+                                                       }
+                                               }
                                        }
                                }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3bdfffb..ee7bad5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -131,6 +131,7 @@ TESTS = \
        delegates/bug638415.vala \
        delegates/bug639751.vala \
        delegates/bug659778.vala \
+       delegates/bug683925.vala \
        delegates/bug703804.vala \
        objects/chainup.vala \
        objects/classes.vala \
diff --git a/tests/delegates/bug683925.vala b/tests/delegates/bug683925.vala
new file mode 100644
index 0000000..5c0ba36
--- /dev/null
+++ b/tests/delegates/bug683925.vala
@@ -0,0 +1,24 @@
+delegate void FooFunc ();
+
+class Foo : Object {
+       bool check = false;
+
+       FooFunc func = default_func;
+
+       public Foo () {
+       }
+
+       void default_func () {
+               check = true;
+       }
+
+       public void run () {
+               func ();
+               assert (check);
+       }
+}
+
+void main(){
+       var foo = new Foo ();
+       foo.run ();
+}


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