[vala/0.12] Fix creation of lambdas inside interface methods



commit 5c8beb70a16587c501bded302428da49271b5300
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sun Apr 24 22:01:31 2011 +0200

    Fix creation of lambdas inside interface methods
    
    Fixes bug 648320.

 codegen/valaccodebasemodule.vala   |    6 +++---
 codegen/valaccodemethodmodule.vala |    2 +-
 tests/Makefile.am                  |    1 +
 tests/methods/bug648320.vala       |   11 +++++++++++
 4 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c466ef9..b759d63 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1712,7 +1712,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			} else {
 				if (in_constructor || (current_method != null && current_method.binding == MemberBinding.INSTANCE) ||
 				           (current_property_accessor != null && current_property_accessor.prop.binding == MemberBinding.INSTANCE)) {
-					data.add_field ("%s *".printf (current_class.get_cname ()), "self");
+					data.add_field ("%s *".printf (current_type_symbol.get_cname ()), "self");
 				}
 
 				if (current_method != null) {
@@ -1776,7 +1776,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				if (in_constructor || (current_method != null && current_method.binding == MemberBinding.INSTANCE &&
 				                              (!(current_method is CreationMethod) || current_method.body != b)) ||
 				           (current_property_accessor != null && current_property_accessor.prop.binding == MemberBinding.INSTANCE)) {
-					var ref_call = new CCodeFunctionCall (get_dup_func_expression (new ObjectType (current_class), b.source_reference));
+					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"));
 
 					ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), "self"), ref_call);
@@ -1865,7 +1865,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				           (current_property_accessor != null && current_property_accessor.prop.binding == MemberBinding.INSTANCE)) {
 					var ma = new MemberAccess.simple ("this");
 					ma.symbol_reference = current_class;
-					ccode.add_expression (get_unref_expression (new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self"), new ObjectType (current_class), ma));
+					ccode.add_expression (get_unref_expression (new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self"), get_data_type_for_symbol (current_type_symbol), ma));
 				}
 			}
 
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 0b8c81a..e8c65e9 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -401,7 +401,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 (current_class.get_cname ()), new CCodeVariableDeclarator ("self"));
+						ccode.add_declaration ("%s *".printf (current_type_symbol.get_cname ()), new CCodeVariableDeclarator ("self"));
 						ccode.add_assignment (new CCodeIdentifier ("self"), cself);
 					}
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f4bb5c1..ef71b55 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,7 @@ TESTS = \
 	methods/bug613483.vala \
 	methods/bug620673.vala \
 	methods/bug646345.vala \
+	methods/bug648320.vala \
 	control-flow/break.vala \
 	control-flow/expressions-conditional.vala \
 	control-flow/for.vala \
diff --git a/tests/methods/bug648320.vala b/tests/methods/bug648320.vala
new file mode 100644
index 0000000..e94c14e
--- /dev/null
+++ b/tests/methods/bug648320.vala
@@ -0,0 +1,11 @@
+public interface Foo : Object {
+	public abstract int i { get; set; }
+
+	public void foo () {
+		int j = 0;
+		SourceFunc bar = () => j == i;
+	}
+}
+
+void main() {
+}



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