Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing uncurried type starting with path. #6089

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ These are only breaking changes for unformatted code.
- Make internal encoding of locations aware of unicode https://github.com/rescript-lang/rescript-compiler/pull/6073
- Fix issue where `foo(x,_)` in uncurried mode would generate a curried function https://github.com/rescript-lang/rescript-compiler/pull/6082
- Fix printing of uncurried application when the lhs is a function definition https://github.com/rescript-lang/rescript-compiler/pull/6084
- Fix parsing uncurried type starting with path https://github.com/rescript-lang/rescript-compiler/pull/6089

#### :nail_care: Polish

Expand Down
15 changes: 8 additions & 7 deletions res_syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4269,15 +4269,11 @@ and parseEs6ArrowType ~attrs p =
let uncurried =
p.uncurried_config |> Res_uncurried.fromDotted ~dotted
in
let loc = mkLoc startPos endPos in
let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in
if uncurried && (paramNum = 1 || p.uncurried_config = Legacy) then
let loc = mkLoc startPos endPos in
let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in
(paramNum - 1, Ast_uncurried.uncurriedType ~loc ~arity tArg, 1)
else
( paramNum - 1,
Ast_helper.Typ.arrow ~loc:(mkLoc startPos endPos) ~attrs argLbl
typ t,
arity + 1 ))
else (paramNum - 1, tArg, arity + 1))
parameters
(List.length parameters, returnType, returnTypeArity + 1)
in
Expand Down Expand Up @@ -4919,6 +4915,11 @@ and parseTypeEquationOrConstrDecl p =
let arrowType =
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType
in
let uncurried = p.uncurried_config <> Legacy in
let arrowType =
if uncurried then Ast_uncurried.uncurriedType ~loc ~arity:1 arrowType
else arrowType
in
let typ = parseTypeAlias p arrowType in
(Some typ, Asttypes.Public, Parsetree.Ptype_abstract)
| _ -> (Some typ, Asttypes.Public, Parsetree.Ptype_abstract))
Expand Down
1 change: 1 addition & 0 deletions res_syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
let needsParens =
match typ.ptyp_desc with
| Ptyp_arrow _ -> true
| _ when Ast_uncurried.typeIsUncurriedFun typ -> true
| _ -> false
in
let doc = printTypExpr ~state typ cmtTbl in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ let t4 = (. type a b) => (l: list<a>, x: a) => list{x, ...l}
let t5 = (type a b) => (. l: list<a>, x: a) => list{x, ...l}
let t6 = (. type a b) => (. l: list<a>, x: a) => list{x, ...l}

type arrowPath1 = (. int) => string
type arrowPath2 = (. I.t) => string
type arrowPath3 = int => string
type arrowPath4 = I.t => string
type callback1 = (. ReactEvent.Mouse.t) => unit as 'callback
type callback2 = (. ReactEvent.Mouse.t) => (unit as 'u)
type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback

@@uncurried.swap

let cApp = foo(. 3)
Expand Down Expand Up @@ -103,3 +111,11 @@ let t0 = (type a b, l: list<a>, x: a) => list{x, ...l}
let t1 = (. type a b, l: list<a>, x: a) => list{x, ...l}
let t2 = (type a b, . l: list<a>, x: a) => list{x, ...l}
let t3 = (. type a b, . l: list<a>, x: a) => list{x, ...l}

type arrowPath1 = int => string
type arrowPath2 = I.t => string
type arrowPath3 = (. int) => string
type arrowPath4 = (. I.t) => string
type callback1 = ReactEvent.Mouse.t => unit as 'callback
type callback2 = ReactEvent.Mouse.t => (unit as 'u)
type callback3 = (ReactEvent.Mouse.t => unit) as 'callback
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ let t5 (type a) (type b) =
((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2])
let t6 (type a) (type b) =
((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2])
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath3 = int -> string
type nonrec arrowPath4 = I.t -> string
type nonrec callback1 =
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
type nonrec callback2 =
(ReactEvent.Mouse.t -> unit as 'u, [ `Has_arity1 ]) function$
type nonrec callback3 =
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
[@@@uncurried.swap ]
let cApp = foo 3
let uApp = ((foo 3)[@res.uapp ])
Expand Down Expand Up @@ -151,4 +161,14 @@ let t0 (type a) (type b) =
((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2])
let t1 (type a) (type b) (l : a list) (x : a) = x :: l
let t2 (type a) (type b) (l : a list) (x : a) = x :: l
let t3 (type a) (type b) (l : a list) (x : a) = x :: l
let t3 (type a) (type b) (l : a list) (x : a) = x :: l
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath3 = int -> string
type nonrec arrowPath4 = I.t -> string
type nonrec callback1 =
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
type nonrec callback2 =
(ReactEvent.Mouse.t -> unit as 'u, [ `Has_arity1 ]) function$
type nonrec callback3 =
(ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback
22 changes: 22 additions & 0 deletions res_syntax/tests/printer/expr/UncurriedByDefault.res
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ let t6 = (. type a b) => (. l: list<a>, x: a) => list{x, ...l}
let () = (x => ignore(x))(3)
let () = ((. x) => ignore(x))(. 3)

type arrowPath1 = (. int) => string
type arrowPath2 = (. I.t) => string
type arrowPath3 = int => string
type arrowPath4 = I.t => string
type callback1 = ReactEvent.Mouse.t => unit as 'callback
type callback2 = ReactEvent.Mouse.t => (unit as 'u)
type callback3 = (ReactEvent.Mouse.t => unit) as 'callback
type callback4 = (. ReactEvent.Mouse.t) => unit as 'callback
type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u)
type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback

@@uncurried.swap

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

let () = (x => ignore(x))(3)
let () = ((. x) => ignore(x))(. 3)

type arrowPath1 = (. int) => string
type arrowPath2 = (. I.t) => string
type arrowPath3 = int => string
type arrowPath4 = I.t => string
type callback1 = (. ReactEvent.Mouse.t) => unit as 'callback
type callback2 = (. ReactEvent.Mouse.t) => (unit as 'u)
type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
type callback4 = ReactEvent.Mouse.t => unit as 'callback
type callback5 = ReactEvent.Mouse.t => (unit as 'u)
type callback6 = (ReactEvent.Mouse.t => unit) as 'callback
22 changes: 22 additions & 0 deletions res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ let t6 = (. type a b, l: list<a>, x: a) => list{x, ...l}
let () = (x => ignore(x))(3)
let () = ((. x) => ignore(x))(. 3)

type arrowPath1 = (. int) => string
type arrowPath2 = (. I.t) => string
type arrowPath3 = int => string
type arrowPath4 = I.t => string
type callback1 = (ReactEvent.Mouse.t => unit) as 'callback
type callback2 = ReactEvent.Mouse.t => (unit as 'u)
type callback3 = (ReactEvent.Mouse.t => unit) as 'callback
type callback4 = ((. ReactEvent.Mouse.t) => unit) as 'callback
type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u)
type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback

@@uncurried.swap

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

let () = (x => ignore(x))(3)
let () = ((. x) => ignore(x))(. 3)

type arrowPath1 = (. int) => string
type arrowPath2 = (. I.t) => string
type arrowPath3 = int => string
type arrowPath4 = I.t => string
type callback1 = ((. ReactEvent.Mouse.t) => unit) as 'callback
type callback2 = (. ReactEvent.Mouse.t) => (unit as 'u)
type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
type callback4 = (ReactEvent.Mouse.t => unit) as 'callback
type callback5 = ReactEvent.Mouse.t => (unit as 'u)
type callback6 = (ReactEvent.Mouse.t => unit) as 'callback