Skip to content

Commit 251e5a0

Browse files
authored
Compiler: fix 827 (#828)
1 parent b9a86d2 commit 251e5a0

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

compiler/lib/eval.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ let drop_exception_handler blocks =
360360
Addr.Map.fold
361361
(fun pc _ blocks ->
362362
match Addr.Map.find pc blocks with
363-
| { branch = Pushtrap (((addr, _) as cont1), _x, _cont2, _)
363+
| { branch = Pushtrap (((addr, _) as cont1), _x, _cont2, addrset)
364364
; handler = parent_hander
365365
; _ } as b -> (
366366
try
@@ -374,8 +374,8 @@ let drop_exception_handler blocks =
374374
assert (Poly.(b.handler <> parent_hander));
375375
let branch =
376376
match b.branch with
377-
| Poptrap (cont, pushtrap) ->
378-
assert (pc = pushtrap);
377+
| Poptrap (((addr, _) as cont), _) ->
378+
assert (Addr.Set.mem addr addrset);
379379
Branch cont
380380
| x -> x
381381
in
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(* Js_of_ocaml compiler
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2019 Hugo Heuzard
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
open Util
20+
21+
(* https://github.com/ocsigen/js_of_ocaml/issues/827 *)
22+
23+
let%expect_test _ =
24+
let compile s =
25+
s
26+
|> Filetype.ocaml_text_of_string
27+
|> Filetype.write_ocaml
28+
|> compile_ocaml_to_cmo
29+
|> compile_cmo_to_javascript ~pretty:true
30+
|> fst
31+
|> parse_js
32+
in
33+
let program =
34+
compile
35+
{|
36+
[@@@ocaml.warning "-26-27"]
37+
let some_name () =
38+
try raise Not_found with
39+
| f ->
40+
(try fun g -> 0 with h -> fun h -> raise Not_found)
41+
(let o =
42+
( try
43+
fun a ->
44+
try try fun c -> 0 with q -> raise (Not_found) with
45+
| f ->
46+
raise Not_found
47+
with
48+
| h ->
49+
(raise Not_found) )
50+
()
51+
in
52+
try
53+
let m = try [] with j -> [] in
54+
true
55+
with
56+
| s ->
57+
true)
58+
|}
59+
in
60+
print_fun_decl program "some_name";
61+
[%expect {| function some_name(param){try {throw Stdlib[8]}catch(_a_){return 0}} |}]

0 commit comments

Comments
 (0)