Skip to content

Commit bd51fc3

Browse files
committed
Tests: exhibit global_deadcode bug
1 parent 69ed235 commit bd51fc3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

compiler/tests-compiler/tailcall.ml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,55 @@ let%expect_test _ =
111111
}
112112
//end
113113
|}]
114+
115+
let%expect_test "global-deadcode-bug" =
116+
let prog =
117+
{|
118+
let log_success () = print_endline "Success!"
119+
type t = { a : bool; b : bool }
120+
let fun1 () =
121+
let g f = if f.b then true else false in
122+
let f x = print_endline "here"; g { a = true; b = false} in
123+
let _ = (f 5000) in
124+
log_success ()
125+
let () = fun1 ()
126+
|}
127+
in
128+
Util.compile_and_run ~flags:[ "--disable"; "inline" ] prog;
129+
[%expect
130+
{|
131+
/tmp/build_b5b39e_dune/jsoo-test3c37fc/test.js:1787
132+
throw err;
133+
^
134+
135+
TypeError: Cannot read properties of undefined (reading '2')
136+
at g (/tmp/build_b5b39e_dune/jsoo-test3c37fc/test.js:1878:23)
137+
at f (/tmp/build_b5b39e_dune/jsoo-test3c37fc/test.js:1879:46)
138+
at fun1 (/tmp/build_b5b39e_dune/jsoo-test3c37fc/test.js:1880:5)
139+
at /tmp/build_b5b39e_dune/jsoo-test3c37fc/test.js:1883:4
140+
at Object.<anonymous> (/tmp/build_b5b39e_dune/jsoo-test3c37fc/test.js:1887:3)
141+
at Module._compile (node:internal/modules/cjs/loader:1734:14)
142+
at Object..js (node:internal/modules/cjs/loader:1899:10)
143+
at Module.load (node:internal/modules/cjs/loader:1469:32)
144+
at Function._load (node:internal/modules/cjs/loader:1286:12)
145+
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
146+
147+
Node.js v23.11.0
148+
149+
here
150+
151+
process exited with error code 7
152+
node test.js
153+
|}];
154+
let program = Util.compile_and_parse ~flags:[ "--disable"; "inline" ] prog in
155+
Util.print_fun_decl program (Some "fun1");
156+
[%expect
157+
{|
158+
function fun1(param){
159+
function g(f){if(f[2]) return;}
160+
function f(x){caml_call1(Stdlib[46], cst_here); return g();}
161+
f(5000);
162+
return log_success(0);
163+
}
164+
//end
165+
|}]

0 commit comments

Comments
 (0)