Skip to content

Commit e55def7

Browse files
committed
Fix parsing type annotations starting with 'a in uncurried mode.
1 parent 91fc35f commit e55def7

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ These are only breaking changes for unformatted code.
4040

4141
#### :nail_care: Polish
4242

43-
- Syntax: process uncurried types explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5784
43+
- Syntax: process uncurried types explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5784 https://github.com/rescript-lang/rescript-compiler/pull/5822
4444
- Syntax: process uncurried function declarations explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5794
4545
- PPX V4: allow uncurried `make` function and treat it like a curried one [#5802](https://github.com/rescript-lang/rescript-compiler/pull/5802) [#5808](https://github.com/rescript-lang/rescript-compiler/pull/5808) [#5812](https://github.com/rescript-lang/rescript-compiler/pull/5812)
4646

lib/4.06.1/unstable/js_playground_compiler.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -166296,7 +166296,12 @@ and parsePolyTypeExpr p =
166296166296
let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in
166297166297
let returnType = parseTypExpr ~alias:false p in
166298166298
let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in
166299-
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
166299+
let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in
166300+
if p.uncurried_by_default then
166301+
Ast_helper.Typ.constr ~loc
166302+
{txt = Ldot (Ldot (Lident "Js", "Fn"), "arity1"); loc}
166303+
[tFun]
166304+
else tFun
166300166305
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
166301166306
| _ -> assert false)
166302166307
| _ -> parseTypExpr p

lib/4.06.1/whole_compiler.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -179728,7 +179728,12 @@ and parsePolyTypeExpr p =
179728179728
let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in
179729179729
let returnType = parseTypExpr ~alias:false p in
179730179730
let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in
179731-
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
179731+
let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in
179732+
if p.uncurried_by_default then
179733+
Ast_helper.Typ.constr ~loc
179734+
{txt = Ldot (Ldot (Lident "Js", "Fn"), "arity1"); loc}
179735+
[tFun]
179736+
else tFun
179732179737
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
179733179738
| _ -> assert false)
179734179739
| _ -> parseTypExpr p

res_syntax/src/res_core.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -3909,7 +3909,12 @@ and parsePolyTypeExpr p =
39093909
let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in
39103910
let returnType = parseTypExpr ~alias:false p in
39113911
let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in
3912-
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
3912+
let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in
3913+
if p.uncurried_by_default then
3914+
Ast_helper.Typ.constr ~loc
3915+
{txt = Ldot (Ldot (Lident "Js", "Fn"), "arity1"); loc}
3916+
[tFun]
3917+
else tFun
39133918
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
39143919
| _ -> assert false)
39153920
| _ -> parseTypExpr p

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
3131
type uu2 = (. unit, unit) => unit
3232
type up2 = (. (), ()) => unit
3333

34+
let uannpoly: (. 'a) => string = xx
35+
let uannint: (. int) => string = xx
36+
3437
@@uncurried
3538

3639
let cApp = foo(. 3)
@@ -67,4 +70,7 @@ type upp = () => () => int
6770
type uu2 = (unit, unit) => unit
6871
type up2 = ((), ()) => unit
6972

70-
let pipe1 = 3->f
73+
let pipe1 = 3->f
74+
75+
let uannpoly: 'a => string = xx
76+
let uannint: int => string = xx

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type nonrec uup = (unit -> int Js.Fn.arity0) Js.Fn.arity1
4040
type nonrec upp = int Js.Fn.arity0 Js.Fn.arity0
4141
type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2
4242
type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2
43+
let (uannpoly : ('a -> string) Js.Fn.arity1) = xx
44+
let (uannint : (int -> string) Js.Fn.arity1) = xx
4345
[@@@uncurried ]
4446
let cApp = foo 3
4547
let uApp = ((foo 3)[@bs ])
@@ -84,4 +86,6 @@ type nonrec uup = (unit -> int Js.Fn.arity0) Js.Fn.arity1
8486
type nonrec upp = int Js.Fn.arity0 Js.Fn.arity0
8587
type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2
8688
type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2
87-
let pipe1 = 3 |.u f
89+
let pipe1 = 3 |.u f
90+
let (uannpoly : ('a -> string) Js.Fn.arity1) = xx
91+
let (uannint : (int -> string) Js.Fn.arity1) = xx

0 commit comments

Comments
 (0)