Skip to content

Commit 0b0aefb

Browse files
authored
Turn some partial application warnings into hints (#11338) (ocaml-flambda#30)
1 parent 2caa9ee commit 0b0aefb

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

testsuite/tests/typing-warnings/application.ml

+2-5
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,10 @@ let _ = g (f 1);;
9494
[%%expect {|
9595
val g : int -> int = <fun>
9696
Line 2, characters 10-15:
97-
2 | let _ = g (f 1);;
98-
^^^^^
99-
Warning 5 [ignored-partial-application]: this function application is partial,
100-
maybe some arguments are missing.
101-
Line 2, characters 10-15:
10297
2 | let _ = g (f 1);;
10398
^^^^^
10499
Error: This expression has type int -> int
105100
but an expression was expected of type int
101+
Hint: This function application is partial,
102+
maybe some arguments are missing.
106103
|}]

typing/typecore.ml

+25-13
Original file line numberDiff line numberDiff line change
@@ -3561,19 +3561,13 @@ and type_expect_
35613561
in
35623562
end_def ();
35633563
unify_var env (newvar()) funct.exp_type;
3564-
let exp =
3565-
{ exp_desc = Texp_apply(funct, args, position);
3566-
exp_loc = loc; exp_extra = [];
3567-
exp_type = ty_res;
3568-
exp_mode = expected_mode.mode;
3569-
exp_attributes = sexp.pexp_attributes;
3570-
exp_env = env } in
3571-
begin
3572-
try rue exp
3573-
with Error (_, _, Expr_type_clash _) as err ->
3574-
Misc.reraise_preserving_backtrace err (fun () ->
3575-
check_partial_application false exp)
3576-
end
3564+
rue {
3565+
exp_desc = Texp_apply(funct, args, position);
3566+
exp_loc = loc; exp_extra = [];
3567+
exp_type = ty_res;
3568+
exp_mode = expected_mode.mode;
3569+
exp_attributes = sexp.pexp_attributes;
3570+
exp_env = env }
35773571
| Pexp_match(sarg, caselist) ->
35783572
let arg_pat_mode, arg_expected_mode =
35793573
match cases_tuple_arity caselist with
@@ -6354,9 +6348,27 @@ let report_literal_type_constraint const = function
63546348
report_literal_type_constraint typ const
63556349
| Some _ | None -> []
63566350
6351+
let report_partial_application = function
6352+
| Some tr -> begin
6353+
let ty =
6354+
match tr.Unification_trace.got.Unification_trace.expanded with
6355+
| None -> tr.Unification_trace.got.Unification_trace.t
6356+
| Some ty -> ty
6357+
in
6358+
let ty = repr ty in
6359+
match ty.desc with
6360+
| Tarrow _ ->
6361+
[ Location.msg
6362+
"@[Hint: This function application is partial,@ \
6363+
maybe some arguments are missing.@]" ]
6364+
| _ -> []
6365+
end
6366+
| None -> []
6367+
63576368
let report_expr_type_clash_hints exp diff =
63586369
match exp with
63596370
| Some (Texp_constant const) -> report_literal_type_constraint const diff
6371+
| Some (Texp_apply _) -> report_partial_application diff
63606372
| _ -> []
63616373
63626374
let report_pattern_type_clash_hints

0 commit comments

Comments
 (0)