Skip to content

Commit 656c3c2

Browse files
committed
Cleanup and type errot tests.
1 parent e759c61 commit 656c3c2

File tree

6 files changed

+60
-13
lines changed

6 files changed

+60
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#### :bug: Bug fix
3939

4040
- Fix recursive untagged variant type checking by delaying well-formedness checks until environment construction completes. [#7320](https://github.com/rescript-lang/rescript/pull/7320)
41+
- Fix incorrect expansion of polymorphic return types in uncurried function applications. https://github.com/rescript-lang/rescript/pull/7338
4142

4243
# 12.0.0-alpha.9
4344

compiler/ml/typecore.ml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,7 +3449,6 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
34493449
34503450
and type_application ?type_clash_context total_app env funct (sargs : sargs) :
34513451
targs * Types.type_expr * bool =
3452-
(* Printf.eprintf "type_application: #args:%d\n" (List.length sargs); *)
34533452
let result_type omitted ty_fun =
34543453
List.fold_left
34553454
(fun ty_fun (l, ty, lv) -> newty2 lv (Tarrow (l, ty, ty_fun, Cok, None)))
@@ -3466,7 +3465,6 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
34663465
| Tvar _ when total_app -> true
34673466
| _ -> false
34683467
in
3469-
(* Printf.eprintf "force_tvar:%b\n" force_tvar; *)
34703468
let has_arity funct =
34713469
let t = funct.exp_type in
34723470
if force_tvar then Some (List.length sargs)
@@ -3552,13 +3550,11 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
35523550
type_unknown_args max_arity ~args ~top_arity:None omitted ty_fun []
35533551
| (l1, sarg1) :: sargl ->
35543552
let l1 = to_noloc l1 in
3555-
(* let lbl_name = label_name l1 in
3556-
Printf.eprintf " type_unknown_args: lbl_name:%s\n" lbl_name; *)
35573553
let ty1, ty2 =
35583554
let ty_fun = expand_head env ty_fun in
35593555
let arity_ok = List.length args < max_arity in
35603556
match ty_fun.desc with
3561-
| Tvar _ when (* l1 = Nolabel || *) force_tvar ->
3557+
| Tvar _ when force_tvar ->
35623558
(* This is a total application when the toplevel type is a polymorphic variable,
35633559
so the function type including arity can be inferred. *)
35643560
let t1 = newvar () and t2 = newvar () in
@@ -3611,11 +3607,9 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
36113607
when sargs <> [] && commu_repr com = Cok && List.length args < max_arity
36123608
->
36133609
let name = label_name l and optional = is_optional l in
3614-
(* Printf.eprintf " type_args: name:%s, optional:%b\n" name optional; *)
36153610
let sargs, omitted, arg =
36163611
match extract_label name sargs with
36173612
| None ->
3618-
(* Printf.eprintf " extract_label: None\n"; *)
36193613
if optional && (total_app || label_assoc Nolabel sargs) then (
36203614
ignored := (l, ty, lv) :: !ignored;
36213615
( sargs,
@@ -3648,14 +3642,8 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
36483642
sargs (* This is the hot path for non-labeled function*)
36493643
in
36503644
if total_app then force_uncurried_type funct;
3651-
(* Printf.eprintf "total_app:%b\n" total_app; *)
36523645
let max_arity = get_max_arity funct in
3653-
(* Printf.eprintf "max_arity:%d\n" max_arity; *)
36543646
let top_arity = if total_app then Some max_arity else None in
3655-
(* Printf.eprintf "top_arity:%s\n"
3656-
(match top_arity with
3657-
| Some _ -> "Some"
3658-
| None -> "None"); *)
36593647
match sargs with
36603648
(* Special case for ignore: avoid discarding warning *)
36613649
| [(Nolabel, sarg)] when is_ignore ~env ~arity:top_arity funct ->
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Warning number 20
3+
/.../fixtures/fun_return_poly1.res:3:15
4+
5+
1 │ let f = (_, ~def=3) => assert(false)
6+
2 │
7+
3 │ let ok = f(1)(2)
8+
4 │ let err = f(1, 2)
9+
5 │
10+
11+
this argument will not be used by the function.
12+
13+
14+
We've found a bug for you!
15+
/.../fixtures/fun_return_poly1.res:4:16
16+
17+
2 │
18+
3 │ let ok = f(1)(2)
19+
4 │ let err = f(1, 2)
20+
5 │
21+
22+
The function applied to this argument has type ('a, ~def: int=?) => 'b
23+
This argument cannot be applied without label
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
Warning number 20
3+
/.../fixtures/fun_return_poly2.res:6:30
4+
5+
4 │ }
6+
5 │
7+
6 │ let ok = r("")(~initialValue=2)
8+
7 │ let err = r("", ~initialValue=2)
9+
8 │
10+
11+
this argument will not be used by the function.
12+
13+
14+
We've found a bug for you!
15+
/.../fixtures/fun_return_poly2.res:7:31
16+
17+
5 │
18+
6 │ let ok = r("")(~initialValue=2)
19+
7 │ let err = r("", ~initialValue=2)
20+
8 │
21+
22+
The function applied to this argument has type
23+
(string, ~wrongLabelName: int=?) => 'a
24+
This argument cannot be applied with label ~initialValue
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let f = (_, ~def=3) => assert(false)
2+
3+
let ok = f(1)(2)
4+
let err = f(1, 2)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let r: (string, ~wrongLabelName: int=?) => 'a = (_s, ~wrongLabelName=3) => {
2+
let _ = wrongLabelName
3+
assert(false)
4+
}
5+
6+
let ok = r("")(~initialValue=2)
7+
let err = r("", ~initialValue=2)

0 commit comments

Comments
 (0)