Skip to content

Commit a709f04

Browse files
committed
remove record spread
1 parent 09fa6dd commit a709f04

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

compiler/ml/cmt_utils.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type action_type =
1616
| RemoveUnusedType
1717
| RemoveUnusedModule
1818
| RemoveRecFlag
19+
| RemoveRecordSpread
1920
| ForceOpen
2021

2122
(* TODO:
@@ -53,6 +54,7 @@ let action_to_string = function
5354
(Longident.flatten new_ident |> String.concat ".")
5455
| RemoveRecFlag -> "RemoveRecFlag"
5556
| ForceOpen -> "ForceOpen"
57+
| RemoveRecordSpread -> "RemoveRecordSpread"
5658

5759
let _add_possible_action : (cmt_action -> unit) ref = ref (fun _ -> ())
5860
let add_possible_action action = !_add_possible_action action
@@ -88,6 +90,9 @@ let emit_possible_actions_from_warning loc w =
8890
{loc; action = RemoveRecFlag; description = "Remove rec flag"}
8991
| Open_shadow_identifier _ | Open_shadow_label_constructor _ ->
9092
add_possible_action {loc; action = ForceOpen; description = "Force open"}
93+
| Useless_record_with ->
94+
add_possible_action
95+
{loc; action = RemoveRecordSpread; description = "Remove `...` spread"}
9196
(*
9297
9398
=== TODO ===
@@ -97,7 +102,6 @@ let emit_possible_actions_from_warning loc w =
97102
(* Use explicit pattern matching instead of literal *) ()
98103
| Unused_pat -> (* Remove pattern *) ()
99104
| Unused_argument -> (* Remove unused argument or prefix with underscore *) ()
100-
| Useless_record_with -> (* Remove `...` spread *) ()
101105
| Nonoptional_label _ -> (* Add `?` to make argument optional *) ()
102106
| Bs_toplevel_expression_unit _ ->
103107
(* Assign to let _ = or pipe to ignore() *) ()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type x = {a: int}
2+
3+
let x = {a: 1}
4+
5+
let f = {a: 1}
6+
7+
/* === AVAILABLE ACTIONS:
8+
- RemoveRecordSpread - Remove `...` spread
9+
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type x = {a: int}
2+
3+
let x = {a: 1}
4+
5+
let f = {...x, a: 1}

tools/src/tools.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,12 @@ module Actions = struct
14571457
if action.loc = expr.pexp_loc then
14581458
let expr = Ast_mapper.default_mapper.expr mapper expr in
14591459
match action.action with
1460+
| RemoveRecordSpread -> (
1461+
match expr with
1462+
| {pexp_desc = Pexp_record (fields, Some _)} ->
1463+
Some
1464+
{expr with pexp_desc = Pexp_record (fields, None)}
1465+
| _ -> None)
14601466
| RewriteIdent {new_ident} -> (
14611467
match expr with
14621468
| {pexp_desc = Pexp_ident ident} ->
@@ -1681,7 +1687,8 @@ module Actions = struct
16811687
| RemoveUnusedType -> List.mem "RemoveUnusedType" filter
16821688
| RemoveUnusedModule -> List.mem "RemoveUnusedModule" filter
16831689
| RemoveRecFlag -> List.mem "RemoveRecFlag" filter
1684-
| ForceOpen -> List.mem "ForceOpen" filter)
1690+
| ForceOpen -> List.mem "ForceOpen" filter
1691+
| RemoveRecordSpread -> List.mem "RemoveRecordSpread" filter)
16851692
in
16861693
match applyActionsToFile path possible_actions with
16871694
| Ok applied ->

0 commit comments

Comments
 (0)