Skip to content

Commit 82ad5e8

Browse files
committed
partially apply function
1 parent d5f73de commit 82ad5e8

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

compiler/ml/cmt_utils.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type action_type =
5252
| ForceOpen
5353
| AssignToUnderscore
5454
| PipeToIgnore
55+
| PartiallyApplyFunction
5556

5657
(* TODO:
5758
- Unused var in patterns (and aliases )*)
@@ -96,6 +97,7 @@ let action_to_string = function
9697
| `Labelled -> "RewriteArgType(Labelled)"
9798
| `Optional -> "RewriteArgType(Optional)"
9899
| `Unlabelled -> "RewriteArgType(Unlabelled)")
100+
| PartiallyApplyFunction -> "PartiallyApplyFunction"
99101

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

compiler/ml/typecore.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,11 +4723,16 @@ let report_error env loc ppf error =
47234723
47244724
if List.length missing_required_args > 0 then (
47254725
(* TODO(actions) Add missing arguments *)
4726-
(* TODO(actions) Partially apply *)
4726+
Cmt_utils.add_possible_action
4727+
{
4728+
loc;
4729+
action = PartiallyApplyFunction;
4730+
description = "Partially apply function";
4731+
};
47274732
fprintf ppf "@,- Missing arguments that must be provided: %s"
47284733
(missing_required_args
47294734
|> List.map (fun v -> "~" ^ v)
4730-
|> String.concat ", ");
4735+
|> String.concat ", "));
47314736
47324737
fprintf ppf
47334738
"@,\
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
@@ -1607,6 +1607,15 @@ module Actions = struct
16071607
else
16081608
(* Other cases when the loc is on something else in the expr *)
16091609
match (expr.pexp_desc, action.action) with
1610+
| ( Pexp_apply ({funct} as apply_args),
1611+
PartiallyApplyFunction )
1612+
when funct.pexp_loc = action.loc ->
1613+
Some
1614+
{
1615+
expr with
1616+
pexp_desc =
1617+
Pexp_apply {apply_args with partial = true};
1618+
}
16101619
| Pexp_apply ({args} as apply), RewriteArgType {to_type}
16111620
->
16121621
let arg_locs =
@@ -1773,6 +1782,8 @@ module Actions = struct
17731782
| RemoveRecordSpread -> List.mem "RemoveRecordSpread" filter
17741783
| AssignToUnderscore -> List.mem "AssignToUnderscore" filter
17751784
| PipeToIgnore -> List.mem "PipeToIgnore" filter
1785+
| PartiallyApplyFunction ->
1786+
List.mem "PartiallyApplyFunction" filter
17761787
| RewriteArgType _ -> List.mem "RewriteArgType" filter)
17771788
in
17781789
match applyActionsToFile path possible_actions with

0 commit comments

Comments
 (0)