فهرست منبع

don't lose block elements when skipping initial block

closes #24
Simon Krajewski 5 ماه پیش
والد
کامیت
0d741d8975
3فایلهای تغییر یافته به همراه38 افزوده شده و 3 حذف شده
  1. 1 1
      src/coro/coroToTexpr.ml
  2. 13 2
      tests/misc/coroutines/src/Main.hx
  3. 24 0
      tests/misc/coroutines/src/issues/aidan/Issue24.hx

+ 1 - 1
src/coro/coroToTexpr.ml

@@ -158,7 +158,7 @@ let block_to_texpr_coroutine ctx cb cls tf_args forbidden_vars econtinuation eco
 			(* If we're skipping our initial state we have to track this for the _hx_state init *)
 			if cb.cb_id = !init_state then
 				init_state := cb_sub.cb_id;
-			loop cb_sub current_el
+			loop cb_sub (current_el @ el)
 		| NextSub (bb_sub,bb_next) ->
 			let next_state_id = loop bb_next [] in
 			let sub_state_id = loop bb_sub [] in

+ 13 - 2
tests/misc/coroutines/src/Main.hx

@@ -1,7 +1,8 @@
 import yield.*;
 
 function main() {
-	utest.UTest.run([
+
+	var cases = [
 		new TestBasic(),
 		new TestTricky(),
 		new TestControlFlow(),
@@ -18,5 +19,15 @@ function main() {
 		// new TestYieldSwitch(),
 		// new TestYieldTryCatch(),
 		// new TestYieldWhile(),
-	]);
+	];
+
+	var runner = new utest.Runner();
+
+	for (eachCase in cases) {
+		runner.addCase(eachCase);
+	}
+	runner.addCases("issues");
+
+    utest.ui.Report.create(runner);
+    runner.run();
 }

+ 24 - 0
tests/misc/coroutines/src/issues/aidan/Issue24.hx

@@ -0,0 +1,24 @@
+package issues.aidan;
+
+class MyCont {
+	public function new() {}
+
+	public function getOrThrow():Any {
+		return "foo";
+	}
+}
+
+@:coroutine
+private function await() {
+	var safe = new MyCont();
+	return {
+		var this1 = safe.getOrThrow();
+		this1;
+	};
+}
+
+class Issue24 extends utest.Test {
+	function test() {
+		Assert.equals("foo", Coroutine.run(await));
+	}
+}