Skip to content

Commit

Permalink
More partial application warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stedolan committed May 13, 2020
1 parent 3a408ff commit 734ccf5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -43,6 +43,8 @@ Working version

### Compiler user-interface and warnings:

- #????: Report partial application warnings on type errors in applications.
(Stephen Dolan, report and testcase by whitequark, review by ??)

### Internal/compiler-libs changes:

Expand Down
20 changes: 20 additions & 0 deletions testsuite/tests/typing-warnings/application.ml
Expand Up @@ -84,3 +84,23 @@ Line 1, characters 19-20:
Warning 20: this argument will not be used by the function.
Exception: Stdlib.Exit.
|}]

let f a b = a + b;;
[%%expect {|
val f : int -> int -> int = <fun>
|}]
let g x = x + 1
let _ = g (f 1);;
[%%expect {|
val g : int -> int = <fun>
Line 2, characters 10-15:
2 | let _ = g (f 1);;
^^^^^
Warning 5: this function application is partial,
maybe some arguments are missing.
Line 2, characters 10-15:
2 | let _ = g (f 1);;
^^^^^
Error: This expression has type int -> int
but an expression was expected of type int
|}]
18 changes: 12 additions & 6 deletions typing/typecore.ml
Expand Up @@ -2709,12 +2709,18 @@ and type_expect_
let (args, ty_res) = type_application env funct sargs in
end_def ();
unify_var env (newvar()) funct.exp_type;
rue {
exp_desc = Texp_apply(funct, args);
exp_loc = loc; exp_extra = [];
exp_type = ty_res;
exp_attributes = sexp.pexp_attributes;
exp_env = env }
let exp =
{ exp_desc = Texp_apply(funct, args);
exp_loc = loc; exp_extra = [];
exp_type = ty_res;
exp_attributes = sexp.pexp_attributes;
exp_env = env } in
begin
try rue exp
with Error (_, _, Expr_type_clash _) as err ->
check_partial_application false exp;
raise err
end
| Pexp_match(sarg, caselist) ->
begin_def ();
let arg = type_exp env sarg in
Expand Down

0 comments on commit 734ccf5

Please sign in to comment.