فهرست منبع

[java] reverse `must_wrap_catches` (see #4134)

Simon Krajewski 10 سال پیش
والد
کامیت
b620c8d7f9
2فایلهای تغییر یافته به همراه28 افزوده شده و 0 حذف شده
  1. 2 0
      gencommon.ml
  2. 26 0
      tests/unit/src/unit/issues/Issue4134.hx

+ 2 - 0
gencommon.ml

@@ -2805,6 +2805,8 @@ struct
 									( (v,catch_map v (run catch)) :: nowrap_catches, must_wrap_catches, catchall )
 						) ([], [], None) catches
 						in
+						(* temp (?) fix for https://github.com/HaxeFoundation/haxe/issues/4134 *)
+						let must_wrap_catches = List.rev must_wrap_catches in
 						(*
 							1st catch all nowrap "the easy way"
 							2nd see if there are any must_wrap or catchall. If there is,

+ 26 - 0
tests/unit/src/unit/issues/Issue4134.hx

@@ -0,0 +1,26 @@
+package unit.issues;
+
+private class A {
+	public function new() { }
+}
+
+private class B extends A { }
+
+class Issue4134 extends Test {
+	function test() {
+		eq("first", throwSomething(new B()));
+		eq("second", throwSomething(new A()));
+	}
+
+	function throwSomething(a:A) {
+		try {
+			throw a;
+		}
+		catch(b:B) {
+			return "first";
+		}
+		catch(a:A) {
+			return "second";
+		}
+	}
+}