Skip to content

Commit ed2e7da

Browse files
authored
Merge pull request #4492 from BuckleScript/gpr_4491
fix #4491, unused list corner case
2 parents 9551c69 + b2310de commit ed2e7da

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

jscomp/core/js_dump.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ let exp_need_paren (e : J.expression) =
167167

168168
| Raw_js_code {code_info = Exp _}
169169
| Fun _
170-
| Caml_block (_,_,_, (Blk_record _ | Blk_module _))
170+
| Caml_block (_,_,_, (Blk_record _ | Blk_module _ | Blk_poly_var _ | Blk_extension | Blk_record_ext _ | Blk_record_inlined _ | Blk_constructor _ ))
171171
| Object _ -> true
172172
| Raw_js_code {code_info = Stmt _ }
173173
| Length _

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ build test/gpr_4280_test.cmi test/gpr_4280_test.cmj : cc test/gpr_4280_test.ml |
325325
build test/gpr_4407_test.cmi test/gpr_4407_test.cmj : cc test/gpr_4407_test.ml | test/debug_mode_value.cmj test/mt.cmj $stdlib
326326
build test/gpr_441.cmi test/gpr_441.cmj : cc test/gpr_441.ml | $stdlib
327327
build test/gpr_4442_test.cmi test/gpr_4442_test.cmj : cc test/gpr_4442_test.ml | test/mt.cmj $stdlib
328+
build test/gpr_4491_test.cmi test/gpr_4491_test.cmj : cc test/gpr_4491_test.ml | $stdlib
328329
build test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
329330
build test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
330331
build test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib

jscomp/test/gpr_4491_test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
4+
function f(xs) {
5+
if (xs !== undefined) {
6+
console.log("side effect");
7+
({
8+
hd: xs,
9+
tl: {
10+
hd: xs,
11+
tl: /* [] */0
12+
}
13+
});
14+
} else {
15+
({
16+
hd: 1,
17+
tl: {
18+
hd: 2,
19+
tl: /* [] */0
20+
}
21+
});
22+
}
23+
console.log("nothing to see here", xs);
24+
25+
}
26+
27+
exports.f = f;
28+
/* No side effect */

jscomp/test/gpr_4491_test.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let f xs =
2+
let unused =
3+
match xs with
4+
| Some (l) -> Js.log "side effect"; [l; l]
5+
| None -> [1; 2]
6+
in
7+
Js.log2 "nothing to see here" xs

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87961,7 +87961,7 @@ let exp_need_paren (e : J.expression) =
8796187961

8796287962
| Raw_js_code {code_info = Exp _}
8796387963
| Fun _
87964-
| Caml_block (_,_,_, (Blk_record _ | Blk_module _))
87964+
| Caml_block (_,_,_, (Blk_record _ | Blk_module _ | Blk_poly_var _ | Blk_extension | Blk_record_ext _ | Blk_record_inlined _ | Blk_constructor _ ))
8796587965
| Object _ -> true
8796687966
| Raw_js_code {code_info = Stmt _ }
8796787967
| Length _

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87961,7 +87961,7 @@ let exp_need_paren (e : J.expression) =
8796187961

8796287962
| Raw_js_code {code_info = Exp _}
8796387963
| Fun _
87964-
| Caml_block (_,_,_, (Blk_record _ | Blk_module _))
87964+
| Caml_block (_,_,_, (Blk_record _ | Blk_module _ | Blk_poly_var _ | Blk_extension | Blk_record_ext _ | Blk_record_inlined _ | Blk_constructor _ ))
8796587965
| Object _ -> true
8796687966
| Raw_js_code {code_info = Stmt _ }
8796787967
| Length _

lib/4.06.1/whole_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381322,7 +381322,7 @@ let exp_need_paren (e : J.expression) =
381322381322

381323381323
| Raw_js_code {code_info = Exp _}
381324381324
| Fun _
381325-
| Caml_block (_,_,_, (Blk_record _ | Blk_module _))
381325+
| Caml_block (_,_,_, (Blk_record _ | Blk_module _ | Blk_poly_var _ | Blk_extension | Blk_record_ext _ | Blk_record_inlined _ | Blk_constructor _ ))
381326381326
| Object _ -> true
381327381327
| Raw_js_code {code_info = Stmt _ }
381328381328
| Length _

0 commit comments

Comments
 (0)