]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Allow using lambdas within enums.
authorMaciej Piechotka <uzytkownik2@gmail.com>
Fri, 23 Aug 2013 20:54:42 +0000 (22:54 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Sat, 21 Dec 2013 09:44:43 +0000 (10:44 +0100)
Fixes bug 659778

codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
tests/delegates/bug659778.vala

index 3af2c2d8c8be863b6094286d545b915344146d56..b3680d574435ffddfdd3c4179fd8ac53615446ba 100644 (file)
@@ -1858,7 +1858,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                data.add_field ("Block%dData *".printf (parent_block_id), "_data%d_".printf (parent_block_id));
                        } else {
                                if (get_this_type () != null) {
-                                       data.add_field ("%s *".printf (get_ccode_name (current_type_symbol)), "self");
+                                       data.add_field (get_ccode_name (get_data_type_for_symbol (current_type_symbol)), "self");
                                }
 
                                if (current_method != null) {
@@ -2021,7 +2021,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        if (get_this_type () != null) {
                                // assign "self" for type parameters
-                               ccode.add_declaration ("%s *".printf (get_ccode_name (current_type_symbol)), new CCodeVariableDeclarator ("self"));
+                               ccode.add_declaration(get_ccode_name (get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self"));
                                ccode.add_assignment (new CCodeIdentifier ("self"), new CCodeMemberAccess.pointer (outer_block, "self"));
                        }
 
@@ -2115,9 +2115,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                ccode.add_expression (unref_call);
                                ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_data%d_".printf (parent_block_id)), new CCodeConstant ("NULL"));
                        } else {
-                               if (get_this_type () != null) {
-                                       // reference count for self is not increased in finalizers
-                                       if (!is_in_destructor ()) {
+                               var this_type = get_this_type ();
+                               if (this_type != null) {
+                                       if (this_type.is_disposable () && !is_in_destructor ()) {
+                                               // reference count for self is not increased in finalizers
                                                var this_value = new GLibValue (get_data_type_for_symbol (current_type_symbol), new CCodeIdentifier ("self"), true);
                                                ccode.add_expression (destroy_value (this_value));
                                        }
@@ -5455,6 +5456,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        set_delegate_target (lambda, delegate_target);
                } else if (get_this_type () != null) {
                        CCodeExpression delegate_target = get_result_cexpression ("self");
+                       delegate_target = convert_to_generic_pointer (delegate_target, get_this_type ());
                        if (expr_owned || delegate_type.is_called_once) {
                                if (get_this_type () != null) {
                                        var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_this_type (), lambda.source_reference));
index 8a4333c3d4526d2c7bbdb4f16672d007d30f281e..d48c03ee12f95118a9722307ea203b74aac39056 100644 (file)
@@ -496,7 +496,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                        // as closures have block data parameter
                                        if (m.binding == MemberBinding.INSTANCE) {
                                                var cself = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self");
-                                               ccode.add_declaration ("%s *".printf (get_ccode_name (current_type_symbol)), new CCodeVariableDeclarator ("self"));
+                                               ccode.add_declaration (get_ccode_name (get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self"));
                                                ccode.add_assignment (new CCodeIdentifier ("self"), cself);
                                        }
 
index 3e60386ce4315b103ab906cb93aae1095d11643d..e73e3c1e498ee27fea5439f925b28b3e8e91ea59 100644 (file)
@@ -3,7 +3,28 @@ delegate G DoSomething<G>(G g);
 void do_something<G> (DoSomething<G> f) {}
 
 enum TE {
-       T
+       T;
+       public void f() {
+               do_something<TE> ((x) => {
+                       switch (this) {
+                       case T:
+                               return T;
+                       default:
+                               assert_not_reached ();
+                       }
+        });
+       }
+       public void g(int i) {
+               do_something<TE> ((x) => {
+                       switch (this) {
+                       case T:
+                               i++;
+                               return T;
+                       default:
+                               assert_not_reached ();
+                       }
+               });
+       }
 }
 
 class Test {
@@ -22,6 +43,9 @@ class Test {
 }
 
 int main() {
+       TE t = TE.T;
+       t.f ();
+       t.g (0);
        Test t2 = new Test ();
        t2.f ();
        return 0;