From: Luca Bruno Date: Sat, 28 May 2011 07:04:25 +0000 (+0200) Subject: codegen: Fix closures in creation methods of classes without base class X-Git-Tag: 0.13.0~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bacac815793f08090e6e658cdca8740b5ce70591;p=thirdparty%2Fvala.git codegen: Fix closures in creation methods of classes without base class Fixes bug 642899. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 2445bc722..021629ddd 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -1749,8 +1749,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), "_data%d_".printf (parent_block_id)), ref_call); } else { - if (in_constructor || (current_method != null && current_method.binding == MemberBinding.INSTANCE && - (!(current_method is CreationMethod) || current_method.body != b)) || + if (in_constructor || (current_method != null && current_method.binding == MemberBinding.INSTANCE && (!(current_method is CreationMethod && current_class != null && current_class.base_class != null) || current_method.body != b)) || (current_property_accessor != null && current_property_accessor.prop.binding == MemberBinding.INSTANCE)) { var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_data_type_for_symbol (current_type_symbol), b.source_reference)); ref_call.add_argument (get_result_cexpression ("self")); diff --git a/tests/Makefile.am b/tests/Makefile.am index de000427a..b02a449f4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -36,6 +36,7 @@ TESTS = \ methods/bug599892.vala \ methods/bug613483.vala \ methods/bug620673.vala \ + methods/bug642899.vala \ methods/bug646345.vala \ methods/bug648320.vala \ control-flow/break.vala \ diff --git a/tests/methods/bug642899.vala b/tests/methods/bug642899.vala new file mode 100644 index 000000000..4fd5dfea9 --- /dev/null +++ b/tests/methods/bug642899.vala @@ -0,0 +1,15 @@ +class Foo { + Object bar; + public Foo () { + Object baz = null; + SourceFunc f = () => { + baz = bar; + return false; + }; + f (); + } +} + +void main () { + new Foo (); +}