Skip to content

Commit e63fc6f

Browse files
cknittclaude
andauthored
Fill generated switch cases with %todo instead of the removed failwith (#9110)
Fill generated switch cases with %todo Why: The exhaustive-switch and add-missing-cases code actions filled new cases with `failwith("TODO")`, but #9052 removed `failwith`, so the generated code no longer compiled. They now use `%todo`, as the exhaustive-switch completion already does. Format modified (code action output): Example: let f = (x: option<int>) => switch x { | Some(_) => 1 } Before (rescript): switch x { | None => failwith("TODO") | Some(_) => 1 } After (rescript): switch x { | None => %todo | Some(_) => 1 } The deprecated-let changelog fragment no longer says that `failwith` and `invalid_arg` warn, since they are removed. Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f3cf487 commit e63fc6f

6 files changed

Lines changed: 18 additions & 17 deletions

File tree

‎analysis/src/codemod.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let transform_opt ~source ~pos ~debug ~typ ~hint =
2121
let cases =
2222
collect_patterns pattern
2323
|> List.map (fun (p : Parsetree.pattern) ->
24-
Ast_helper.Exp.case p (Type_utils.Codegen.mk_fail_with_exp ()))
24+
Ast_helper.Exp.case p (Type_utils.Codegen.mk_todo_exp ()))
2525
in
2626
let result = ref None in
2727
let mk_iterator ~pos ~result =

‎analysis/src/type_utils.ml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,10 @@ let rec context_path_from_core_type (core_type : Parsetree.core_type) =
10351035
| _ -> None
10361036

10371037
module Codegen = struct
1038-
let mk_fail_with_exp () =
1039-
Ast_helper.Exp.apply
1040-
(Ast_helper.Exp.ident {txt = Lident "failwith"; loc = Location.none})
1041-
[(Nolabel, Ast_helper.Exp.constant (Ast_helper.Const.string "TODO"))]
1038+
(* Placeholder body for generated cases: `%todo`, which compiles (with a
1039+
warning) and throws at runtime. *)
1040+
let mk_todo_exp () =
1041+
Ast_helper.Exp.extension ({txt = "todo"; loc = Location.none}, PStr [])
10421042

10431043
let mk_construct_pat ?payload name =
10441044
Ast_helper.Pat.construct
@@ -1160,7 +1160,7 @@ module Codegen = struct
11601160
Some
11611161
(patterns
11621162
|> List.map (fun (pat : Parsetree.pattern) ->
1163-
Ast_helper.Exp.case pat (mk_fail_with_exp ())))
1163+
Ast_helper.Exp.case pat (mk_todo_exp ())))
11641164
end
11651165

11661166
let get_module_path_relative_to_env ~debug ~(env : Query_env.t) ~env_from_item
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fill cases added by the exhaustive-switch and add-missing-cases code actions with `%todo` instead of the removed `failwith("TODO")`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Warn when another module uses a `@deprecated` `let` binding from a module without an interface file. As a result, `failwith` and `invalid_arg`, deprecated since v12, now emit their deprecation warning when used.
1+
- Warn when another module uses a `@deprecated` `let` binding from a module without an interface file.

‎tests/analysis_tests/tests/src/expected/Codemod.res.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Codemod AddMissingCasessrc/Codemod.res 3:10
22
switch (v1, v2) {
33
// ^c-a (#valid, #valid) | (#invalid, _)
44
| (#valid, #invalid) => ()
5-
| (#valid, #valid) => failwith("TODO")
6-
| (#invalid, _) => failwith("TODO")
5+
| (#valid, #valid) => %todo
6+
| (#invalid, _) => %todo
77
}
88

‎tests/analysis_tests/tests/src/expected/ExhaustiveSwitch.res.txt‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ TextDocumentEdit: ExhaustiveSwitch.res
128128
newText:
129129
<--here
130130
switch x->getV {
131-
| One => failwith("TODO")
132-
| Two => failwith("TODO")
133-
| Three(_) => failwith("TODO")
131+
| One => %todo
132+
| Two => %todo
133+
| Three(_) => %todo
134134
}
135135

136136
Xform src/ExhaustiveSwitch.res 36:4
@@ -152,11 +152,11 @@ TextDocumentEdit: ExhaustiveSwitch.res
152152
newText:
153153
<--here
154154
switch vvv {
155-
| None => failwith("TODO")
156-
| Some(_) => failwith("TODO")
157-
| Some(One) => failwith("TODO")
158-
| Some(Two) => failwith("TODO")
159-
| Some(Three(_)) => failwith("TODO")
155+
| None => %todo
156+
| Some(_) => %todo
157+
| Some(One) => %todo
158+
| Some(Two) => %todo
159+
| Some(Three(_)) => %todo
160160
}
161161

162162

0 commit comments

Comments
 (0)