diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f840b5a6..3a6be1fa65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index 7361a1e22d..690f59a84f 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -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 diff --git a/jscomp/test/gpr_1438.js b/jscomp/test/gpr_1438.js index 6e286ffb3e..1007c0d56d 100644 --- a/jscomp/test/gpr_1438.js +++ b/jscomp/test/gpr_1438.js @@ -12,22 +12,6 @@ function actionKey(key, a, b, c, d, e) { return e; case 116 : return b; - case 100 : - case 101 : - case 102 : - case 103 : - case 104 : - case 105 : - case 108 : - case 109 : - case 110 : - case 111 : - case 112 : - case 113 : - case 114 : - case 115 : - case 117 : - break; case 99 : case 118 : return a; diff --git a/jscomp/test/gpr_1698_test.js b/jscomp/test/gpr_1698_test.js index 1d14c72e7e..2a0fb865d9 100644 --- a/jscomp/test/gpr_1698_test.js +++ b/jscomp/test/gpr_1698_test.js @@ -168,8 +168,6 @@ function compare(context, state, _a, _b) { switch (b.TAG) { case "Pow" : return 1; - case "Gcd" : - return -1; default: return -1; } diff --git a/jscomp/test/mario_game.js b/jscomp/test/mario_game.js index 95150eadbc..6983adb8ad 100644 --- a/jscomp/test/mario_game.js +++ b/jscomp/test/mario_game.js @@ -2377,25 +2377,6 @@ function keydown(evt) { case 83 : pressed_keys.down = true; break; - case 67 : - case 69 : - case 70 : - case 71 : - case 72 : - case 73 : - case 74 : - case 75 : - case 76 : - case 77 : - case 78 : - case 79 : - case 80 : - case 81 : - case 82 : - case 84 : - case 85 : - case 86 : - break; case 87 : pressed_keys.up = true; break; diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js index a93a34a8c1..041f35e63e 100644 --- a/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/ocaml_re_test.js @@ -3541,23 +3541,6 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }); case 90 : return "Last_end_of_line"; - case 58 : - case 59 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - case 91 : - case 92 : - case 93 : - case 94 : - case 95 : - case 96 : - return { - TAG: "Set", - _0: single(c) - }; case 98 : return alt$1({ hd: "Beg_of_word", diff --git a/jscomp/test/string_test.js b/jscomp/test/string_test.js index 2744674448..30571ddd1b 100644 --- a/jscomp/test/string_test.js +++ b/jscomp/test/string_test.js @@ -46,11 +46,6 @@ function gg(x) { case 4 : a = 6; break; - case 5 : - case 6 : - case 7 : - a = 8; - break; case 8 : a = 7; break; diff --git a/jscomp/test/typeof_test.js b/jscomp/test/typeof_test.js index 44dcf4b821..0985549075 100644 --- a/jscomp/test/typeof_test.js +++ b/jscomp/test/typeof_test.js @@ -8,9 +8,6 @@ function string_or_number(x) { var ty = Js_types.classify(x); if (typeof ty !== "object") { switch (ty) { - case "JSFalse" : - case "JSTrue" : - return false; default: return false; } diff --git a/lib/es6/caml_format.js b/lib/es6/caml_format.js index e0452d321b..a67a4a58fe 100644 --- a/lib/es6/caml_format.js +++ b/lib/es6/caml_format.js @@ -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; @@ -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; diff --git a/lib/es6/genlex.js b/lib/es6/genlex.js index 09a9b041b3..362e36152b 100644 --- a/lib/es6/genlex.js +++ b/lib/es6/genlex.js @@ -240,9 +240,6 @@ function make_lexer(keywords) { case 94 : exit = 3; break; - case 95 : - exit = 2; - break; case 91 : case 93 : case 96 : @@ -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; @@ -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) { diff --git a/lib/js/caml_format.js b/lib/js/caml_format.js index 47e458a5da..bb6e0c34eb 100644 --- a/lib/js/caml_format.js +++ b/lib/js/caml_format.js @@ -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; @@ -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; diff --git a/lib/js/genlex.js b/lib/js/genlex.js index 27b3c7d43d..ff3731e9c6 100644 --- a/lib/js/genlex.js +++ b/lib/js/genlex.js @@ -240,9 +240,6 @@ function make_lexer(keywords) { case 94 : exit = 3; break; - case 95 : - exit = 2; - break; case 91 : case 93 : case 96 : @@ -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; @@ -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) {