[vala] codegen: Fix closures in creation methods of classes without base class



commit bacac815793f08090e6e658cdca8740b5ce70591
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat May 28 09:04:25 2011 +0200

    codegen: Fix closures in creation methods of classes without base class
    
    Fixes bug 642899.

 codegen/valaccodebasemodule.vala |    3 +--
 tests/Makefile.am                |    1 +
 tests/methods/bug642899.vala     |   15 +++++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2445bc7..021629d 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 de00042..b02a449 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 0000000..4fd5dfe
--- /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 ();
+}



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