Skip to content

Commit 884a7da

Browse files
committed
partially apply function
1 parent 8986037 commit 884a7da

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

compiler/ml/cmt_utils.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type action_type =
2121
| ForceOpen
2222
| AssignToUnderscore
2323
| PipeToIgnore
24+
| PartiallyApplyFunction
2425

2526
(* TODO:
2627
- Unused var in patterns (and aliases )*)
@@ -65,6 +66,7 @@ let action_to_string = function
6566
| `Labelled -> "RewriteArgType(Labelled)"
6667
| `Optional -> "RewriteArgType(Optional)"
6768
| `Unlabelled -> "RewriteArgType(Unlabelled)")
69+
| PartiallyApplyFunction -> "PartiallyApplyFunction"
6870

6971
let _add_possible_action : (cmt_action -> unit) ref = ref (fun _ -> ())
7072
let add_possible_action action = !_add_possible_action action

compiler/ml/typecore.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,13 +4656,18 @@ let report_error env loc ppf error =
46564656
46574657
if not is_fallback then fprintf ppf "@,";
46584658
4659-
if List.length missing_required_args > 0 then
4659+
if List.length missing_required_args > 0 then (
46604660
(* TODO(actions) Add missing arguments *)
4661-
(* TODO(actions) Partially apply *)
4661+
Cmt_utils.add_possible_action
4662+
{
4663+
loc;
4664+
action = PartiallyApplyFunction;
4665+
description = "Partially apply function";
4666+
};
46624667
fprintf ppf "@,- Missing arguments that must be provided: %s"
46634668
(missing_required_args
46644669
|> List.map (fun v -> "~" ^ v)
4665-
|> String.concat ", ");
4670+
|> String.concat ", "));
46664671
46674672
if List.length superfluous_args > 0 then
46684673
(* TODO(actions) Remove arguments *)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// actionFilter=PartiallyApplyFunction
2+
let x = (~a, ~b) => a + b
3+
let y = x(~a=2, ...) + 2
4+
5+
/* === AVAILABLE ACTIONS:
6+
- PartiallyApplyFunction - Partially apply function
7+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// actionFilter=PartiallyApplyFunction
2+
let x = (~a, ~b) => a + b
3+
let y = x(~a=2) + 2

tools/src/tools.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,15 @@ module Actions = struct
16061606
else
16071607
(* Other cases when the loc is on something else in the expr *)
16081608
match (expr.pexp_desc, action.action) with
1609+
| ( Pexp_apply ({funct} as apply_args),
1610+
PartiallyApplyFunction )
1611+
when funct.pexp_loc = action.loc ->
1612+
Some
1613+
{
1614+
expr with
1615+
pexp_desc =
1616+
Pexp_apply {apply_args with partial = true};
1617+
}
16091618
| Pexp_apply ({args} as apply), RewriteArgType {to_type}
16101619
->
16111620
let arg_locs =
@@ -1772,6 +1781,8 @@ module Actions = struct
17721781
| RemoveRecordSpread -> List.mem "RemoveRecordSpread" filter
17731782
| AssignToUnderscore -> List.mem "AssignToUnderscore" filter
17741783
| PipeToIgnore -> List.mem "PipeToIgnore" filter
1784+
| PartiallyApplyFunction ->
1785+
List.mem "PartiallyApplyFunction" filter
17751786
| RewriteArgType _ -> List.mem "RewriteArgType" filter)
17761787
in
17771788
match applyActionsToFile path possible_actions with

0 commit comments

Comments
 (0)