Skip to content

Fix issue with typing application and polymorphic types. #7338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#### :bug: Bug fix

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

# 12.0.0-alpha.9

Expand Down
4 changes: 3 additions & 1 deletion compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3554,7 +3554,9 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
let ty_fun = expand_head env ty_fun in
let arity_ok = List.length args < max_arity in
match ty_fun.desc with
| Tvar _ ->
| Tvar _ when force_tvar ->
(* This is a total application when the toplevel type is a polymorphic variable,
so the function type including arity can be inferred. *)
let t1 = newvar () and t2 = newvar () in
if ty_fun.level >= t1.level && not_identity funct.exp_desc then
Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Warning number 20
/.../fixtures/fun_return_poly1.res:3:15

1 │ let f = (_, ~def=3) => assert(false)
2 │
3 │ let ok = f(1)(2)
4 │ let err = f(1, 2)
5 │

this argument will not be used by the function.


We've found a bug for you!
/.../fixtures/fun_return_poly1.res:4:16

2 │
3 │ let ok = f(1)(2)
4 │ let err = f(1, 2)
5 │

The function applied to this argument has type ('a, ~def: int=?) => 'b
This argument cannot be applied without label
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

Warning number 20
/.../fixtures/fun_return_poly2.res:6:30

4 │ }
5 │
6 │ let ok = r("")(~initialValue=2)
7 │ let err = r("", ~initialValue=2)
8 │

this argument will not be used by the function.


We've found a bug for you!
/.../fixtures/fun_return_poly2.res:7:31

5 │
6 │ let ok = r("")(~initialValue=2)
7 │ let err = r("", ~initialValue=2)
8 │

The function applied to this argument has type
(string, ~wrongLabelName: int=?) => 'a
This argument cannot be applied with label ~initialValue
4 changes: 4 additions & 0 deletions tests/build_tests/super_errors/fixtures/fun_return_poly1.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let f = (_, ~def=3) => assert(false)

let ok = f(1)(2)
let err = f(1, 2)
7 changes: 7 additions & 0 deletions tests/build_tests/super_errors/fixtures/fun_return_poly2.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let r: (string, ~wrongLabelName: int=?) => 'a = (_s, ~wrongLabelName=3) => {
let _ = wrongLabelName
assert(false)
}

let ok = r("")(~initialValue=2)
let err = r("", ~initialValue=2)