[vala] codegen: Fix look-up of next closure block



commit a90b9d2e467ab77ccef7bcd6c26f310cda3b6f2f
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Apr 2 10:09:10 2011 +0200

    codegen: Fix look-up of next closure block
    
    Methods that are not closures don't capture parent blocks.
    
    Fixes bug 646345.

 codegen/valaccodebasemodule.vala |   16 +++++++++++-----
 tests/Makefile.am                |    1 +
 tests/methods/bug646345.vala     |   16 ++++++++++++++++
 3 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ecc80d7..0d9cb22 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -177,20 +177,26 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public unowned Block? next_closure_block (Symbol sym) {
-		unowned Block block = null;
 		while (true) {
-			block = sym as Block;
-			if (!(sym is Block || sym is Method)) {
+			unowned Method method = sym as Method;
+			if (method != null && !method.closure) {
+				// parent blocks are not captured by this method
+				break;
+			}
+
+			unowned Block block = sym as Block;
+			if (method == null && block == null) {
 				// no closure block
 				break;
 			}
+
 			if (block != null && block.captured) {
 				// closure block found
-				break;
+				return block;
 			}
 			sym = sym.parent_symbol;
 		}
-		return block;
+		return null;
 	}
 
 	public CCodeFile header_file;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 411f348..b643d8a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -34,6 +34,7 @@ TESTS = \
 	methods/bug599892.vala \
 	methods/bug613483.vala \
 	methods/bug620673.vala \
+	methods/bug646345.vala \
 	control-flow/break.vala \
 	control-flow/expressions-conditional.vala \
 	control-flow/for.vala \
diff --git a/tests/methods/bug646345.vala b/tests/methods/bug646345.vala
new file mode 100644
index 0000000..29b84e4
--- /dev/null
+++ b/tests/methods/bug646345.vala
@@ -0,0 +1,16 @@
+void main() {
+	var outervar = "outerfoo";
+	SourceFunc firstfunc = () => {
+		outervar = "outerbar";
+		return false;
+	};
+
+	SourceFunc secondfunc = () => {
+		var innervar = "innerfoo";
+		SourceFunc innerfunc = () => {
+			innervar = "innerbar";
+			return false;
+		};
+		return false;
+	};
+}



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