Skip to content

Commit 8a67dc6

Browse files
[cs] fixed cs.Lib.rethrow (closes #9738)
1 parent 6cbdcc7 commit 8a67dc6

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

extra/CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
flash : fixed `VerifyError` exception when `Void` end up as an argument type after inlining (#9678)
1010
php : fixed runtime error "cannot use temporary expression in write context" for call arguments passed by reference
1111
php : support @:native("") for extern classes (#6448)
12+
cs : fixed `cs.Lib.rethrow` (#9738)
1213
python : support @:native("") for extern classes (#6448)
1314
nullsafety: fixed `@:nullSafety(Off)` in closures inside of constructors (#9643)
1415
nullsafety: fixed "Type not found NullSafetyMode_Impl_" (#9483)

src/context/common.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ type exceptions_config = {
9292
For example `throw 123` is compiled to `throw (cast Exception.thrown(123):ec_base_throw)`
9393
*)
9494
ec_base_throw : path;
95+
(*
96+
Checks if throwing this expression is a special case for current target
97+
and should not be modified.
98+
*)
99+
ec_special_throw : texpr -> bool;
95100
}
96101

97102
type var_scope =
@@ -389,6 +394,7 @@ let default_config =
389394
ec_native_catches = [];
390395
ec_wildcard_catch = (["StdTypes"],"Dynamic");
391396
ec_base_throw = (["StdTypes"],"Dynamic");
397+
ec_special_throw = fun _ -> false;
392398
};
393399
pf_scoping = {
394400
vs_scope = BlockScope;
@@ -469,7 +475,7 @@ let get_config com =
469475
default_config with
470476
pf_static = false;
471477
pf_uses_utf16 = false;
472-
pf_exceptions = {
478+
pf_exceptions = { default_config.pf_exceptions with
473479
ec_native_throws = [
474480
["php"],"Throwable";
475481
["haxe"],"Exception";
@@ -516,6 +522,7 @@ let get_config com =
516522
];
517523
ec_wildcard_catch = (["cs";"system"],"Exception");
518524
ec_base_throw = (["cs";"system"],"Exception");
525+
ec_special_throw = fun e -> e.eexpr = TIdent "__rethrow__"
519526
};
520527
pf_scoping = {
521528
vs_scope = FunctionScope;
@@ -530,7 +537,7 @@ let get_config com =
530537
pf_overload = true;
531538
pf_supports_threads = true;
532539
pf_this_before_super = false;
533-
pf_exceptions = {
540+
pf_exceptions = { default_config.pf_exceptions with
534541
ec_native_throws = [
535542
["java";"lang"],"RuntimeException";
536543
["haxe"],"Exception";
@@ -557,7 +564,7 @@ let get_config com =
557564
pf_static = false;
558565
pf_capture_policy = CPLoopVars;
559566
pf_uses_utf16 = false;
560-
pf_exceptions = {
567+
pf_exceptions = { default_config.pf_exceptions with
561568
ec_native_throws = [
562569
["python";"Exceptions"],"BaseException";
563570
];

src/filters/exceptions.ml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,23 @@ let rec contains_throw_or_try e =
150150
to be thrown.
151151
*)
152152
let requires_wrapped_throw cfg e =
153-
(*
154-
Check if `e` is of `haxe.Exception` type directly (not a descendant),
155-
but not a `new haxe.Exception(...)` expression.
156-
In this case we delegate the decision to `haxe.Exception.thrown(e)`.
157-
Because it could happen to be a wrapper for a wildcard catch.
158-
*)
159-
let is_stored_haxe_exception() =
160-
is_haxe_exception ~check_parent:false e.etype
161-
&& match e.eexpr with
162-
| TNew(_,_,_) -> false
163-
| _ -> true
164-
in
165-
is_stored_haxe_exception()
166-
|| (not (is_native_throw cfg e.etype) && not (is_haxe_exception e.etype))
153+
if cfg.ec_special_throw e then
154+
false
155+
else
156+
(*
157+
Check if `e` is of `haxe.Exception` type directly (not a descendant),
158+
but not a `new haxe.Exception(...)` expression.
159+
In this case we delegate the decision to `haxe.Exception.thrown(e)`.
160+
Because it could happen to be a wrapper for a wildcard catch.
161+
*)
162+
let is_stored_haxe_exception() =
163+
is_haxe_exception ~check_parent:false e.etype
164+
&& match e.eexpr with
165+
| TNew(_,_,_) -> false
166+
| _ -> true
167+
in
168+
is_stored_haxe_exception()
169+
|| (not (is_native_throw cfg e.etype) && not (is_haxe_exception e.etype))
167170

168171
(**
169172
Generate a throw of a native exception.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package unit.issues;
2+
3+
class Issue9738 extends Test {
4+
#if cs
5+
function test() {
6+
try {
7+
try {
8+
throw new haxe.Exception("Hello");
9+
} catch (e) {
10+
cs.Lib.rethrow(e);
11+
}
12+
assert();
13+
} catch(e) {
14+
noAssert();
15+
}
16+
}
17+
#end
18+
}

0 commit comments

Comments
 (0)