|
| 1 | +(* Js_of_ocaml compiler |
| 2 | + * http://www.ocsigen.org/js_of_ocaml/ |
| 3 | + * Copyright (C) 2025 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 | + |
| 20 | +open Util |
| 21 | + |
| 22 | +let%expect_test "inlining" = |
| 23 | + let p = |
| 24 | + {| |
| 25 | +module X : sig |
| 26 | +end = struct |
| 27 | + external fun_to_js : (unit -> unit) -> unit = "foo" |
| 28 | + |
| 29 | + let[@tail_mod_cons] rec aux f = f () :: aux f |
| 30 | + |
| 31 | + let map_to_list f = aux (fun x -> f x) |
| 32 | + |
| 33 | + let embedded_input_file_handler _ = |
| 34 | + fun_to_js (fun _ -> |
| 35 | + let _ = map_to_list (fun _ -> assert false) in |
| 36 | + ()) |
| 37 | + |
| 38 | + let _ = embedded_input_file_handler () |
| 39 | +end |
| 40 | + |} |
| 41 | + in |
| 42 | + let p = compile_and_parse ~flags:[ "--debug"; "js_assign" ] p in |
| 43 | + print_program p; |
| 44 | + [%expect.unreachable] |
| 45 | +[@@expect.uncaught_exn {| |
| 46 | + (* CR expect_test_collector: This test expectation appears to contain a backtrace. |
| 47 | + This is strongly discouraged as backtraces are fragile. |
| 48 | + Please change this test to not include a backtrace. *) |
| 49 | + (Failure "non-zero exit code") |
| 50 | + Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 213, characters 18-35 |
| 51 | + Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string.loop in file "compiler/tests-compiler/util/util.ml", line 169, characters 4-52 |
| 52 | + Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14 |
| 53 | + |
| 54 | + Trailing output |
| 55 | + --------------- |
| 56 | + (function(globalThis){ |
| 57 | + "use strict"; |
| 58 | + var |
| 59 | + runtime = globalThis.jsoo_runtime, |
| 60 | + caml_maybe_attach_backtrace = runtime.caml_maybe_attach_backtrace; |
| 61 | + function caml_call1(f, a0){ |
| 62 | + return (f.l >= 0 ? f.l : f.l = f.length) === 1 |
| 63 | + ? f(a0) |
| 64 | + : runtime.caml_call_gen(f, [a0]); |
| 65 | + } |
| 66 | + var |
| 67 | + global_data = runtime.caml_get_global_data(), |
| 68 | + Assert_failure = global_data.Assert_failure, |
| 69 | + _a_ = [0, runtime.caml_string_of_jsbytes("test.ml"), 12, 38], |
| 70 | + dummy = 0; |
| 71 | + runtime.foo |
| 72 | + (function(param){ |
| 73 | + caml_call1(<v30{f}>, dummy); |
| 74 | + throw caml_maybe_attach_backtrace([0, Assert_failure, _a_], 1); |
| 75 | + }); |
| 76 | + var X = [0], Test = [0, X]; |
| 77 | + runtime.caml_register_global(2, Test, "Test"); |
| 78 | + return; |
| 79 | + } |
| 80 | + (globalThis)); |
| 81 | + Some variables escaped: <v30{f}> |
| 82 | + /home/hugo/js_of_ocaml/_build/default/compiler/bin-js_of_ocaml/js_of_ocaml.exe: You found a bug. Please report it at https://github.com/ocsigen/js_of_ocaml/issues : |
| 83 | + Error: File "compiler/lib/js_assign.ml", line 503, characters 5-11: Assertion failed |
| 84 | + |
| 85 | + process exited with error code 125 |
| 86 | + /home/hugo/js_of_ocaml/_build/default/compiler/bin-js_of_ocaml/js_of_ocaml.exe --pretty --debug var --sourcemap --effects=disabled --disable=use-js-string --disable header --debug js_assign --Werror test.cmo -o test.js |
| 87 | + |}] |
0 commit comments