瀏覽代碼

[jvm] deal with complex static inits

closes #11998
Simon Krajewski 7 月之前
父節點
當前提交
97c3e5a5a2
共有 2 個文件被更改,包括 22 次插入1 次删除
  1. 7 1
      src/optimization/analyzer.ml
  2. 15 0
      tests/unit/src/unit/issues/Issue11998.hx

+ 7 - 1
src/optimization/analyzer.ml

@@ -1009,11 +1009,17 @@ module Run = struct
 			match e.eexpr with
 			| TFunction tf ->
 				let get_t t = if ExtType.is_void t then tf.tf_type else t in
+				let doesnt_like_complex_expressions = match actx.com.platform with
+					| Cpp | Hl | Jvm ->
+						true
+					| _ ->
+						false
+				in
 				let rec loop e = match e.eexpr with
 					| TBlock [e1] ->
 						loop e1
 					(* If there's a complex expression, keep the function and generate a call to it. *)
-					| TBlock _ | TIf _ | TSwitch _ | TTry _ when actx.com.platform = Cpp || actx.com.platform = Hl ->
+					| TBlock _ | TIf _ | TSwitch _ | TTry _ when doesnt_like_complex_expressions ->
 						raise Exit
 					(* Remove generated return *)
 					| TReturn (Some e) ->

+ 15 - 0
tests/unit/src/unit/issues/Issue11998.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+class Issue11998 extends unit.Test {
+	static var caughtVar = {
+		try {
+			throw "foo";
+		} catch (s:String) {
+			s;
+		}
+	}
+
+	public function test() {
+		eq("foo", caughtVar);
+	}
+}