Skip to content

Fix redundant branches in generated switch body, fixes #6671 #6672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Fix making the static import for the dynamic import of external ffi https://github.com/rescript-lang/rescript-compiler/pull/6664
- Fix local type variables breaking react components. https://github.com/rescript-lang/rescript-compiler/pull/6665
- Fix remove redundant branches in generated switch body. https://github.com/rescript-lang/rescript-compiler/pull/6672

#### :nail-care: Polish

Expand Down
5 changes: 5 additions & 0 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ and compile_general_cases :
break still should not be printed (it will be continuned)
TOOD: disabled temporarily since it's not perfect yet *)
morph_declare_to_assign cxt (fun cxt declaration ->
(* Exclude cases that are the same as the default if the default is defined *)
let cases = match default with
| Default lam -> List.filter (fun (_, lam1) -> not (Lam.eq_approx lam lam1)) cases
| _ -> cases
in
let default =
match default with
| Complete -> None
Expand Down
16 changes: 0 additions & 16 deletions jscomp/test/gpr_1438.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions jscomp/test/gpr_1698_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions jscomp/test/mario_game.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions jscomp/test/ocaml_re_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions jscomp/test/string_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions jscomp/test/typeof_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions lib/es6/caml_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function parse_sign_and_base(s) {
case 43 :
i = i + 1 | 0;
break;
case 44 :
break;
case 45 :
sign = -1;
i = i + 1 | 0;
Expand Down Expand Up @@ -417,19 +415,6 @@ function parse_format(fmt) {
};
_i = j;
continue ;
case 33 :
case 34 :
case 36 :
case 37 :
case 38 :
case 39 :
case 40 :
case 41 :
case 42 :
case 44 :
case 47 :
exit = 1;
break;
case 48 :
f.filter = "0";
_i = i + 1 | 0;
Expand Down
12 changes: 0 additions & 12 deletions lib/es6/genlex.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ function make_lexer(keywords) {
case 94 :
exit = 3;
break;
case 95 :
exit = 2;
break;
case 91 :
case 93 :
case 96 :
Expand Down Expand Up @@ -535,12 +532,6 @@ function make_lexer(keywords) {
case 114 :
Stream.junk(strm__);
return /* '\r' */13;
case 111 :
case 112 :
case 113 :
case 115 :
Stream.junk(strm__);
return c1;
case 116 :
Stream.junk(strm__);
return /* '\t' */9;
Expand Down Expand Up @@ -617,9 +608,6 @@ function make_lexer(keywords) {
RE_EXN_ID: Stream.Failure,
Error: new Error()
};
case 41 :
Stream.junk(strm__);
continue ;
case 42 :
Stream.junk(strm__);
while(true) {
Expand Down
15 changes: 0 additions & 15 deletions lib/js/caml_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function parse_sign_and_base(s) {
case 43 :
i = i + 1 | 0;
break;
case 44 :
break;
case 45 :
sign = -1;
i = i + 1 | 0;
Expand Down Expand Up @@ -417,19 +415,6 @@ function parse_format(fmt) {
};
_i = j;
continue ;
case 33 :
case 34 :
case 36 :
case 37 :
case 38 :
case 39 :
case 40 :
case 41 :
case 42 :
case 44 :
case 47 :
exit = 1;
break;
case 48 :
f.filter = "0";
_i = i + 1 | 0;
Expand Down
12 changes: 0 additions & 12 deletions lib/js/genlex.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ function make_lexer(keywords) {
case 94 :
exit = 3;
break;
case 95 :
exit = 2;
break;
case 91 :
case 93 :
case 96 :
Expand Down Expand Up @@ -535,12 +532,6 @@ function make_lexer(keywords) {
case 114 :
Stream.junk(strm__);
return /* '\r' */13;
case 111 :
case 112 :
case 113 :
case 115 :
Stream.junk(strm__);
return c1;
case 116 :
Stream.junk(strm__);
return /* '\t' */9;
Expand Down Expand Up @@ -617,9 +608,6 @@ function make_lexer(keywords) {
RE_EXN_ID: Stream.Failure,
Error: new Error()
};
case 41 :
Stream.junk(strm__);
continue ;
case 42 :
Stream.junk(strm__);
while(true) {
Expand Down