Skip to content

Commit 5091233

Browse files
committed
tentative fix for #2608
1 parent ddbb6ae commit 5091233

File tree

9 files changed

+429
-206
lines changed

9 files changed

+429
-206
lines changed

jscomp/core/bs_conditional_initial.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
let setup_env () =
2727
#if BS_DEBUG then
28-
Js_config.set_debug_file "test_bool_equal.ml";
28+
Js_config.set_debug_file "gpr_2608_test.ml";
2929
#end
3030
Lexer.replace_directive_bool "BS" true;
3131
Lexer.replace_directive_string "BS_VERSION" Bs_version.version

jscomp/core/lam_compile.ml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -676,26 +676,37 @@ and
676676
(* Invariant: if [should_return], then [st] will not be [NeedValue] *)
677677
->
678678
compile_lambda cxt (Lam.sequand l r )
679-
| _ ->
680-
679+
| {should_return = ReturnFalse } ->
680+
let new_cxt = {cxt with st = NeedValue} in
681681
match
682-
compile_lambda
683-
{cxt with st = NeedValue; should_return = ReturnFalse} l with
682+
compile_lambda new_cxt l with
684683
| { value = None } -> assert false
685684
| {block = l_block; value = Some l_expr} ->
686-
match
687-
compile_lambda
688-
{cxt with st = NeedValue; should_return = ReturnFalse} r
685+
match compile_lambda new_cxt r
689686
with
690687
| { value = None } -> assert false
691-
| {block = r_block; value = Some r_expr} ->
692-
let args_code = Ext_list.append l_block r_block in
693-
let exp = E.and_ l_expr r_expr in
688+
| {block = []; value = Some r_expr}
689+
->
694690
Js_output.output_of_block_and_expression
695691
st
696-
should_return lam args_code exp
692+
should_return lam l_block (E.and_ l_expr r_expr)
693+
| { block = r_block; value = Some r_expr} ->
694+
let v = Ext_ident.create_tmp () in
695+
Js_output.output_of_block_and_expression
696+
st
697+
should_return
698+
lam
699+
(S.define_variable ~kind:Variable v E.caml_false ::
700+
l_block @
701+
[S.if_ l_expr
702+
(r_block @ [
703+
S.assign v r_expr
704+
]
705+
)
706+
]
707+
)
708+
(E.var v)
697709
end
698-
699710
| Lprim {primitive = Psequor; args = [l;r]}
700711
->
701712
begin match cxt with
@@ -1184,7 +1195,9 @@ and
11841195
when branches are minimial (less than 2)
11851196
*)
11861197
let v = Ext_ident.create_tmp () in
1187-
Js_output.make (S.declare_variable ~kind:Variable v :: compile_whole {cxt with st = Assign v})
1198+
Js_output.make
1199+
(S.declare_variable ~kind:Variable v ::
1200+
compile_whole {cxt with st = Assign v})
11881201
~value:(E.var v)
11891202

11901203
| Declare (kind,id) ->

jscomp/test/.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ gpr_2316_test.cmj : mt.cmj ../runtime/js.cmj
304304
gpr_2474.cmj :
305305
gpr_2487.cmj : ../others/belt.cmj
306306
gpr_2503_test.cmj : mt.cmj ../runtime/js.cmj
307+
gpr_2608_test.cmj : mt.cmj ../stdlib/list.cmj
307308
gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi
308309
gpr_441.cmj :
309310
gpr_459_test.cmj : mt.cmj

jscomp/test/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
241241
gpr_2487\
242242
gpr_2503_test\
243243
block_alias_test\
244+
gpr_2608_test\
244245
# bs_uncurry_test
245246
# needs Lam to get rid of Uncurry arity first
246247
# simple_derive_test

jscomp/test/ext_string_test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,23 @@ function trim(s) {
5959
var i = 0;
6060
var j = s.length;
6161
while((function () {
62-
var u = s.charCodeAt(i);
63-
return +(i < j && (u === /* "\t" */9 || u === /* "\n" */10 || u === /* " " */32));
62+
var tmp = /* false */0;
63+
if (i < j) {
64+
var u = s.charCodeAt(i);
65+
tmp = +(u === /* "\t" */9 || u === /* "\n" */10 || u === /* " " */32);
66+
}
67+
return tmp;
6468
})()) {
6569
i = i + 1 | 0;
6670
};
6771
var k = j - 1 | 0;
6872
while((function () {
69-
var u = s.charCodeAt(k);
70-
return +(k >= i && (u === /* "\t" */9 || u === /* "\n" */10 || u === /* " " */32));
73+
var tmp = /* false */0;
74+
if (k >= i) {
75+
var u = s.charCodeAt(k);
76+
tmp = +(u === /* "\t" */9 || u === /* "\n" */10 || u === /* " " */32);
77+
}
78+
return tmp;
7179
})()) {
7280
k = k - 1 | 0;
7381
};

jscomp/test/gpr_2608_test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
var List = require("../../lib/js/list.js");
5+
6+
var suites = [/* [] */0];
7+
8+
var test_id = [0];
9+
10+
function eq(loc, x, y) {
11+
return Mt.eq_suites(test_id, suites, loc, x, y);
12+
}
13+
14+
var oppHeroes = /* :: */[
15+
0,
16+
/* [] */0
17+
];
18+
19+
var tmp = /* false */0;
20+
21+
if (List.length(/* [] */0) > 0) {
22+
var x = List.filter((function () {
23+
return +(List.hd(/* [] */0) <= 1000);
24+
}))(oppHeroes);
25+
tmp = +(List.length(x) === 0);
26+
}
27+
28+
var huntGrootCondition = tmp;
29+
30+
eq("File \"gpr_2608_test.ml\", line 17, characters 5-12", huntGrootCondition, /* false */0);
31+
32+
Mt.from_pair_suites("gpr_2608_test.ml", suites[0]);
33+
34+
var nearestGroots = /* [] */0;
35+
36+
exports.suites = suites;
37+
exports.test_id = test_id;
38+
exports.eq = eq;
39+
exports.nearestGroots = nearestGroots;
40+
exports.oppHeroes = oppHeroes;
41+
exports.huntGrootCondition = huntGrootCondition;
42+
/* huntGrootCondition Not a pure module */

jscomp/test/gpr_2608_test.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
let suites : Mt.pair_suites ref = ref []
3+
let test_id = ref 0
4+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
5+
6+
7+
let nearestGroots = []
8+
9+
let oppHeroes = [0]
10+
let huntGrootCondition =
11+
List.length nearestGroots > 0 &&
12+
let x = (List.filter (fun h -> (List.hd nearestGroots) <= 1000)
13+
oppHeroes) in
14+
List.length x = 0
15+
16+
let () =
17+
eq __LOC__ huntGrootCondition false
18+
let () =
19+
Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)