Skip to content

Commit 0ea4a48

Browse files
committed
Compiler: expose bug from gh2083
1 parent 3ceafdf commit 0ea4a48

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

compiler/tests-compiler/tailcall.ml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,74 @@ let%expect_test "global-deadcode-bug" =
141141
}
142142
//end
143143
|}]
144+
145+
let%expect_test "_" =
146+
let prog =
147+
{|
148+
type t =
149+
| Zero
150+
| Succ of t
151+
152+
let rules (rules : t -> t) : t -> t =
153+
function
154+
| Zero -> Succ Zero
155+
| Succ n -> Succ (rules n)
156+
157+
let rec step n =
158+
rules step n
159+
160+
let rec grow (iters : int) (n : t) : t =
161+
if iters < 0 then n else
162+
(grow [@tailcall]) (iters - 1) (step n)
163+
|}
164+
in
165+
let program = Util.compile_and_parse ~flags:[ "--debug"; "js_assign" ] prog in
166+
Util.print_fun_decl program (Some "grow");
167+
[%expect.unreachable]
168+
[@@expect.uncaught_exn {|
169+
(* CR expect_test_collector: This test expectation appears to contain a backtrace.
170+
This is strongly discouraged as backtraces are fragile.
171+
Please change this test to not include a backtrace. *)
172+
(Failure "non-zero exit code")
173+
Raised at Stdlib__Buffer.add_channel in file "buffer.ml", line 213, characters 18-35
174+
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
175+
Called from Jsoo_compiler_expect_tests_helper__Util.channel_to_string in file "compiler/tests-compiler/util/util.ml", line 172, characters 7-14
176+
177+
Trailing output
178+
---------------
179+
(function(globalThis){
180+
"use strict";
181+
var runtime = globalThis.jsoo_runtime;
182+
function caml_call1(f, a0){
183+
return (f.l >= 0 ? f.l : f.l = f.length) === 1
184+
? f(a0)
185+
: runtime.caml_call_gen(f, [a0]);
186+
}
187+
var _a_ = [0, 0];
188+
function rules(rules, param){
189+
if(! param) return _a_;
190+
var n = param[1];
191+
return [0, caml_call1(rules, n)];
192+
}
193+
function step(n){return rules(step, n);}
194+
function grow(iters$1, n$0){
195+
var iters = iters$1, n = n$0;
196+
for(;;){
197+
if(0 > iters) return n;
198+
var n$1 = rules(<v26{step}>, n), iters$0 = iters - 1 | 0;
199+
iters = iters$0;
200+
n = n$1;
201+
}
202+
}
203+
var Test = [0, rules, step, grow];
204+
runtime.caml_register_global(1, Test, "Test");
205+
return;
206+
}
207+
(globalThis));
208+
Some variables escaped: <v26{step}>
209+
/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 :
210+
Error: File "compiler/lib/js_assign.ml", line 503, characters 5-11: Assertion failed
211+
212+
process exited with error code 125
213+
/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
214+
|}]

0 commit comments

Comments
 (0)