Skip to content

Commit e54b688

Browse files
committed
Tests: exhibit inlining bug
1 parent eaea1a1 commit e54b688

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

compiler/tests-compiler/dune.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,21 @@
464464
(preprocess
465465
(pps ppx_expect)))
466466

467+
(library
468+
;; compiler/tests-compiler/gh2106.ml
469+
(name gh2106_15)
470+
(enabled_if true)
471+
(modules gh2106)
472+
(libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper)
473+
(inline_tests
474+
(enabled_if true)
475+
(deps
476+
(file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe)
477+
(file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe)))
478+
(flags (:standard -open Jsoo_compiler_expect_tests_helper))
479+
(preprocess
480+
(pps ppx_expect)))
481+
467482
(library
468483
;; compiler/tests-compiler/gh747.ml
469484
(name gh747_15)

compiler/tests-compiler/gh2106.ml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Comments
 (0)