Skip to content

Commit 6b841cf

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

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-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

+7-1
Original file line numberDiff line numberDiff line change
@@ -166277,6 +166277,7 @@ and parsePolyTypeExpr p =
166277166277
let startPos = p.Parser.startPos in
166278166278
match p.Parser.token with
166279166279
| SingleQuote -> (
166280+
(* XX here *)
166280166281
let vars = parseTypeVarList p in
166281166282
match vars with
166282166283
| _v1 :: _v2 :: _ ->
@@ -166296,7 +166297,12 @@ and parsePolyTypeExpr p =
166296166297
let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in
166297166298
let returnType = parseTypExpr ~alias:false p in
166298166299
let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in
166299-
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
166300+
let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in
166301+
if p.uncurried_by_default then
166302+
Ast_helper.Typ.constr ~loc
166303+
{txt = Ldot (Ldot (Lident "Js", "Fn"), "arity1"); loc}
166304+
[tFun]
166305+
else tFun
166300166306
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
166301166307
| _ -> assert false)
166302166308
| _ -> parseTypExpr p

lib/4.06.1/whole_compiler.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -179709,6 +179709,7 @@ and parsePolyTypeExpr p =
179709179709
let startPos = p.Parser.startPos in
179710179710
match p.Parser.token with
179711179711
| SingleQuote -> (
179712+
(* XX here *)
179712179713
let vars = parseTypeVarList p in
179713179714
match vars with
179714179715
| _v1 :: _v2 :: _ ->
@@ -179728,7 +179729,12 @@ and parsePolyTypeExpr p =
179728179729
let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in
179729179730
let returnType = parseTypExpr ~alias:false p in
179730179731
let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in
179731-
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
179732+
let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in
179733+
if p.uncurried_by_default then
179734+
Ast_helper.Typ.constr ~loc
179735+
{txt = Ldot (Ldot (Lident "Js", "Fn"), "arity1"); loc}
179736+
[tFun]
179737+
else tFun
179732179738
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
179733179739
| _ -> assert false)
179734179740
| _ -> parseTypExpr p

res_syntax/src/res_core.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,7 @@ and parsePolyTypeExpr p =
38903890
let startPos = p.Parser.startPos in
38913891
match p.Parser.token with
38923892
| SingleQuote -> (
3893+
(* XX here *)
38933894
let vars = parseTypeVarList p in
38943895
match vars with
38953896
| _v1 :: _v2 :: _ ->
@@ -3909,7 +3910,12 @@ and parsePolyTypeExpr p =
39093910
let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in
39103911
let returnType = parseTypExpr ~alias:false p in
39113912
let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in
3912-
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
3913+
let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in
3914+
if p.uncurried_by_default then
3915+
Ast_helper.Typ.constr ~loc
3916+
{txt = Ldot (Ldot (Lident "Js", "Fn"), "arity1"); loc}
3917+
[tFun]
3918+
else tFun
39133919
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
39143920
| _ -> assert false)
39153921
| _ -> 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)