Skip to content

Commit 4242f3b

Browse files
authored
Process uncurried application in the type checker. (#5835)
* Process uncurried application in the type checker. - Do the processing of uncurried application in the type checker. - Add support for default arguments in uncurried functions. - Add custom error messages for uncurried application. - Uncurried pipe processing does not require special handling. The current encoding is based on arity. To support default arguments one cannot just look at the number of supplied arguments, but to know whether the required arguments are supplied one needs to inspect the function type. * Give error when uncurried application tries to use label from result type. * clean up error message that is now not possible * Add examples of uncurried functions with default arguments. * Update CHANGELOG.md * clean up
1 parent ac2d922 commit 4242f3b

22 files changed

+530
-416
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
subset of the arguments, and return a curried type with the remaining ones https://github.com/rescript-lang/rescript-compiler/pull/5805
2222
- Add support for uncurried externals https://github.com/rescript-lang/rescript-compiler/pull/5815 https://github.com/rescript-lang/rescript-compiler/pull/5819 https://github.com/rescript-lang/rescript-compiler/pull/5830
2323
- Parser/Printer: unify uncurried functions of arity 0, and of arity 1 taking unit. There's now only arity 1 in the source language. https://github.com/rescript-lang/rescript-compiler/pull/5825
24+
- Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835
2425

2526

2627
#### :boom: Breaking Change

jscomp/build_tests/super_errors/expected/arity_mismatch.res.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
2 │ let makeVariables = makeVar(.~f=f => f)
77
3 │
88

9-
This function expected 2 arguments, but got 1
9+
This uncurried function has type (. ~f: 'a => 'a, unit) => int
10+
It is applied with 1 arguments but it requires 2.

jscomp/build_tests/super_errors/expected/arity_mismatch2.res.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
2 │ let makeVariables = makeVar(. 1, 2, 3)
77
3 │
88

9-
This function expected 2 arguments, but got 3
9+
This uncurried function has type (. 'a, unit) => int
10+
It is applied with 3 arguments but it requires 2.

jscomp/build_tests/super_errors/expected/method_arity_mismatch.res.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
4 │ }
99
5 │
1010

11-
This function expected 2 arguments, but got 1
11+
This uncurried function has type (. int, int) => unit
12+
It is applied with 1 arguments but it requires 2.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/uncurried_wrong_label.res:3:18
4+
5+
1 │ let foo = (. ~x) => { let _ = (); (~y) => x+y }
6+
2 │ // This looks too far into the return type
7+
3 │ let d = foo(. ~y=3)
8+
4 │
9+
10+
The function applied to this argument has type (. ~x: int, ~y: int) => int
11+
This argument cannot be applied with label ~y

jscomp/build_tests/super_errors/expected/warnings4.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
14 │
1111

1212
You forgot to handle a possible case here, for example:
13-
#second(_) | #fourth | #third
13+
#second(_) | #fourth | #third

jscomp/build_tests/super_errors/expected/warnings5.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ Either bind these labels explicitly or add ', _' to the pattern.
187187
60 │
188188

189189
You forgot to handle a possible case here, for example:
190-
(_, true)
190+
(_, true)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let foo = (. ~x) => { let _ = (); (~y) => x+y }
2+
// This looks too far into the return type
3+
let d = foo(. ~y=3)

jscomp/frontend/ast_attributes.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ let locg = Location.none
341341
let is_bs (attr : attr) =
342342
match attr with { Location.txt = "bs"; _ }, _ -> true | _ -> false
343343

344-
let is_res_uapp (attr : attr) =
345-
match attr with { Location.txt = "res.uapp"; _ }, _ -> true | _ -> false
344+
let res_uapp : attr = ({ txt = "res.uapp"; loc = locg }, Ast_payload.empty)
346345

347346
let bs_get : attr = ({ txt = "bs.get"; loc = locg }, Ast_payload.empty)
348347

jscomp/frontend/ast_attributes.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ val is_bs : attr -> bool
7373
val is_bs_as : attr -> bool *)
7474

7575
(* Attribute for uncurried application coming from the ReScript parser *)
76-
val is_res_uapp : attr -> bool
76+
val res_uapp : attr
7777

7878
val bs_get : attr
7979

0 commit comments

Comments
 (0)