diff --git a/CHANGELOG.md b/CHANGELOG.md index a9582b35bd..f248204808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index ffbfc0ac42..4d14ddc3f2 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -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; diff --git a/tests/build_tests/super_errors/expected/fun_return_poly1.res.expected b/tests/build_tests/super_errors/expected/fun_return_poly1.res.expected new file mode 100644 index 0000000000..e19cffd36e --- /dev/null +++ b/tests/build_tests/super_errors/expected/fun_return_poly1.res.expected @@ -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 \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/fun_return_poly2.res.expected b/tests/build_tests/super_errors/expected/fun_return_poly2.res.expected new file mode 100644 index 0000000000..54fcade1ac --- /dev/null +++ b/tests/build_tests/super_errors/expected/fun_return_poly2.res.expected @@ -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 \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/fun_return_poly1.res b/tests/build_tests/super_errors/fixtures/fun_return_poly1.res new file mode 100644 index 0000000000..49922cd8e8 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/fun_return_poly1.res @@ -0,0 +1,4 @@ +let f = (_, ~def=3) => assert(false) + +let ok = f(1)(2) +let err = f(1, 2) diff --git a/tests/build_tests/super_errors/fixtures/fun_return_poly2.res b/tests/build_tests/super_errors/fixtures/fun_return_poly2.res new file mode 100644 index 0000000000..f9c465d95b --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/fun_return_poly2.res @@ -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)