Skip to content

Commit 5802387

Browse files
committed
Fix parsing uncurried type starting with path.
1 parent 8d07220 commit 5802387

File tree

7 files changed

+91
-8
lines changed

7 files changed

+91
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ These are only breaking changes for unformatted code.
6060
- Make internal encoding of locations aware of unicode https://github.com/rescript-lang/rescript-compiler/pull/6073
6161
- Fix issue where `foo(x,_)` in uncurried mode would generate a curried function https://github.com/rescript-lang/rescript-compiler/pull/6082
6262
- Fix printing of uncurried application when the lhs is a function definition https://github.com/rescript-lang/rescript-compiler/pull/6084
63+
- Fix parsing uncurried type starting with path https://github.com/rescript-lang/rescript-compiler/pull/6089
6364

6465
#### :nail_care: Polish
6566

res_syntax/src/res_core.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -4269,15 +4269,11 @@ and parseEs6ArrowType ~attrs p =
42694269
let uncurried =
42704270
p.uncurried_config |> Res_uncurried.fromDotted ~dotted
42714271
in
4272+
let loc = mkLoc startPos endPos in
4273+
let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in
42724274
if uncurried && (paramNum = 1 || p.uncurried_config = Legacy) then
4273-
let loc = mkLoc startPos endPos in
4274-
let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in
42754275
(paramNum - 1, Ast_uncurried.uncurriedType ~loc ~arity tArg, 1)
4276-
else
4277-
( paramNum - 1,
4278-
Ast_helper.Typ.arrow ~loc:(mkLoc startPos endPos) ~attrs argLbl
4279-
typ t,
4280-
arity + 1 ))
4276+
else (paramNum - 1, tArg, arity + 1))
42814277
parameters
42824278
(List.length parameters, returnType, returnTypeArity + 1)
42834279
in
@@ -4919,6 +4915,11 @@ and parseTypeEquationOrConstrDecl p =
49194915
let arrowType =
49204916
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
49214917
in
4918+
let uncurried = p.uncurried_config <> Legacy in
4919+
let arrowType =
4920+
if uncurried then Ast_uncurried.uncurriedType ~loc ~arity:1 arrowType
4921+
else arrowType
4922+
in
49224923
let typ = parseTypeAlias p arrowType in
49234924
(Some typ, Asttypes.Public, Parsetree.Ptype_abstract)
49244925
| _ -> (Some typ, Asttypes.Public, Parsetree.Ptype_abstract))

res_syntax/src/res_printer.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
16441644
let needsParens =
16451645
match typ.ptyp_desc with
16461646
| Ptyp_arrow _ -> true
1647+
| _ when Ast_uncurried.typeIsUncurriedFun typ -> true
16471648
| _ -> false
16481649
in
16491650
let doc = printTypExpr ~state typ cmtTbl in

res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ let t4 = (. type a b) => (l: list<a>, x: a) => list{x, ...l}
5050
let t5 = (type a b) => (. l: list<a>, x: a) => list{x, ...l}
5151
let t6 = (. type a b) => (. l: list<a>, x: a) => list{x, ...l}
5252

53+
type arrowPath1 = (. int) => string
54+
type arrowPath2 = (. I.t) => string
55+
type arrowPath3 = int => string
56+
type arrowPath4 = I.t => string
57+
type callback1 = (. ReactEvent.Mouse.t) => unit as 'callback
58+
type callback2 = (. ReactEvent.Mouse.t) => (unit as 'u)
59+
type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
60+
5361
@@uncurried.swap
5462

5563
let cApp = foo(. 3)
@@ -103,3 +111,11 @@ let t0 = (type a b, l: list<a>, x: a) => list{x, ...l}
103111
let t1 = (. type a b, l: list<a>, x: a) => list{x, ...l}
104112
let t2 = (type a b, . l: list<a>, x: a) => list{x, ...l}
105113
let t3 = (. type a b, . l: list<a>, x: a) => list{x, ...l}
114+
115+
type arrowPath1 = int => string
116+
type arrowPath2 = I.t => string
117+
type arrowPath3 = (. int) => string
118+
type arrowPath4 = (. I.t) => string
119+
type callback1 = ReactEvent.Mouse.t => unit as 'callback
120+
type callback2 = ReactEvent.Mouse.t => (unit as 'u)
121+
type callback3 = (ReactEvent.Mouse.t => unit) as 'callback

res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt

+21-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ let t5 (type a) (type b) =
7676
((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2])
7777
let t6 (type a) (type b) =
7878
((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2])
79+
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
80+
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
81+
type nonrec arrowPath3 = int -> string
82+
type nonrec arrowPath4 = I.t -> string
83+
type nonrec callback1 =
84+
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
85+
type nonrec callback2 =
86+
(ReactEvent.Mouse.t -> unit as 'u, [ `Has_arity1 ]) function$
87+
type nonrec callback3 =
88+
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
7989
[@@@uncurried.swap ]
8090
let cApp = foo 3
8191
let uApp = ((foo 3)[@res.uapp ])
@@ -151,4 +161,14 @@ let t0 (type a) (type b) =
151161
((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2])
152162
let t1 (type a) (type b) (l : a list) (x : a) = x :: l
153163
let t2 (type a) (type b) (l : a list) (x : a) = x :: l
154-
let t3 (type a) (type b) (l : a list) (x : a) = x :: l
164+
let t3 (type a) (type b) (l : a list) (x : a) = x :: l
165+
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
166+
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
167+
type nonrec arrowPath3 = int -> string
168+
type nonrec arrowPath4 = I.t -> string
169+
type nonrec callback1 =
170+
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
171+
type nonrec callback2 =
172+
(ReactEvent.Mouse.t -> unit as 'u, [ `Has_arity1 ]) function$
173+
type nonrec callback3 =
174+
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback

res_syntax/tests/printer/expr/UncurriedByDefault.res

+22
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ let t6 = (. type a b) => (. l: list<a>, x: a) => list{x, ...l}
6060
let () = (x => ignore(x))(3)
6161
let () = ((. x) => ignore(x))(. 3)
6262

63+
type arrowPath1 = (. int) => string
64+
type arrowPath2 = (. I.t) => string
65+
type arrowPath3 = int => string
66+
type arrowPath4 = I.t => string
67+
type callback1 = ReactEvent.Mouse.t => unit as 'callback
68+
type callback2 = ReactEvent.Mouse.t => (unit as 'u)
69+
type callback3 = (ReactEvent.Mouse.t => unit) as 'callback
70+
type callback4 = (. ReactEvent.Mouse.t) => unit as 'callback
71+
type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u)
72+
type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback
73+
6374
@@uncurried.swap
6475

6576
let cApp = foo(. 3)
@@ -121,3 +132,14 @@ let t3 = (. type a b, . l: list<a>, x: a) => list{x, ...l}
121132

122133
let () = (x => ignore(x))(3)
123134
let () = ((. x) => ignore(x))(. 3)
135+
136+
type arrowPath1 = (. int) => string
137+
type arrowPath2 = (. I.t) => string
138+
type arrowPath3 = int => string
139+
type arrowPath4 = I.t => string
140+
type callback1 = (. ReactEvent.Mouse.t) => unit as 'callback
141+
type callback2 = (. ReactEvent.Mouse.t) => (unit as 'u)
142+
type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
143+
type callback4 = ReactEvent.Mouse.t => unit as 'callback
144+
type callback5 = ReactEvent.Mouse.t => (unit as 'u)
145+
type callback6 = (ReactEvent.Mouse.t => unit) as 'callback

res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt

+22
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ let t6 = (. type a b, l: list<a>, x: a) => list{x, ...l}
6060
let () = (x => ignore(x))(3)
6161
let () = ((. x) => ignore(x))(. 3)
6262

63+
type arrowPath1 = (. int) => string
64+
type arrowPath2 = (. I.t) => string
65+
type arrowPath3 = int => string
66+
type arrowPath4 = I.t => string
67+
type callback1 = (ReactEvent.Mouse.t => unit) as 'callback
68+
type callback2 = ReactEvent.Mouse.t => (unit as 'u)
69+
type callback3 = (ReactEvent.Mouse.t => unit) as 'callback
70+
type callback4 = ((. ReactEvent.Mouse.t) => unit) as 'callback
71+
type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u)
72+
type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback
73+
6374
@@uncurried.swap
6475

6576
let cApp = foo(. 3)
@@ -121,3 +132,14 @@ let t3 = (. type a b, l: list<a>, x: a) => list{x, ...l}
121132

122133
let () = (x => ignore(x))(3)
123134
let () = ((. x) => ignore(x))(. 3)
135+
136+
type arrowPath1 = (. int) => string
137+
type arrowPath2 = (. I.t) => string
138+
type arrowPath3 = int => string
139+
type arrowPath4 = I.t => string
140+
type callback1 = ((. ReactEvent.Mouse.t) => unit) as 'callback
141+
type callback2 = (. ReactEvent.Mouse.t) => (unit as 'u)
142+
type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
143+
type callback4 = (ReactEvent.Mouse.t => unit) as 'callback
144+
type callback5 = ReactEvent.Mouse.t => (unit as 'u)
145+
type callback6 = (ReactEvent.Mouse.t => unit) as 'callback

0 commit comments

Comments
 (0)