Skip to content

Commit

Permalink
remove newly redundant parens
Browse files Browse the repository at this point in the history
Signed-off-by: David Vulakh <[email protected]>
  • Loading branch information
dvulakh committed Aug 9, 2024
1 parent b546a6b commit 47f3b20
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
9 changes: 7 additions & 2 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1957,8 +1957,13 @@ end = struct
| { ast= {ptyp_desc= Ptyp_poly _; _}
; ctx= Typ {ptyp_desc= Ptyp_arrow _; _} } ->
true
| {ast= {ptyp_desc= Ptyp_var (_, l); _}; ctx= _} when Option.is_some l ->
true
| {ast= {ptyp_desc= Ptyp_var (_, l); _}; ctx} when Option.is_some l -> (
match ctx with
| Typ {ptyp_desc= Ptyp_constr (_, _ :: _ :: _); _} ->
(* annotations on one of multiple arguments to a type do not
warrant parens *)
false
| _ -> true )
| { ast= {ptyp_desc= Ptyp_tuple ((Some _, _) :: _); _}
; ctx= Typ {ptyp_desc= Ptyp_arrow (args, _, _); _} }
when List.exists args ~f:(fun arg -> arg.pap_type == typ) ->
Expand Down
21 changes: 7 additions & 14 deletions test/passing/tests/layout_annotation-erased.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@ let f : (_ : immediate) -> unit = fun _ -> ()
let g : (_ : value) -> unit = fun _ -> ()
let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false
let f : ((_ : any), _) t = ()
let g : (_, (_ : any)) t = ()
let f : ((_ : any), _) t -> t = ()
let g : (_, (_ : any)) t -> t = ()

let f
: (_, (_ : any), (_ : any), (_ : any), (_ : any), (_ : any), (_ : any), (_ : any)) t
-> t
=
()
;;

let g : (_, _, _, _, _, _, _, _, (_ : any)) t -> t = ()
let f : (_ : any, _) t = ()
let g : (_, _ : any) t = ()
let f : (_ : any, _) t -> t = ()
let g : (_, _ : any) t -> t = ()
let f : (_, _ : any, _ : any, _ : any, _ : any, _ : any, _ : any, _ : any) t -> t = ()
let g : (_, _, _, _, _, _, _, _, _ : any) t -> t = ()

(********************************************)
(* Test 3: Annotation on types in functions *)
Expand Down Expand Up @@ -211,7 +204,7 @@ let f_val : ('a : value). 'a -> 'a = fun x -> f_imm x

type (_ : value) g = MkG : ('a : immediate). 'a g
type t = int as (_ : immediate)
type t = (('a : value), ('b : value)) t2
type t = ('a : value, 'b : value) t2
type ('a, 'b) t = ('a : value) * ('b : value)

class c : object
Expand Down
21 changes: 7 additions & 14 deletions test/passing/tests/layout_annotation.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@ let f : (_ : immediate) -> unit = fun _ -> ()
let g : (_ : value) -> unit = fun _ -> ()
let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false
let f : ((_ : any), _) t = ()
let g : (_, (_ : any)) t = ()
let f : ((_ : any), _) t -> t = ()
let g : (_, (_ : any)) t -> t = ()

let f
: (_, (_ : any), (_ : any), (_ : any), (_ : any), (_ : any), (_ : any), (_ : any)) t
-> t
=
()
;;

let g : (_, _, _, _, _, _, _, _, (_ : any)) t -> t = ()
let f : (_ : any, _) t = ()
let g : (_, _ : any) t = ()
let f : (_ : any, _) t -> t = ()
let g : (_, _ : any) t -> t = ()
let f : (_, _ : any, _ : any, _ : any, _ : any, _ : any, _ : any, _ : any) t -> t = ()
let g : (_, _, _, _, _, _, _, _, _ : any) t -> t = ()

(********************************************)
(* Test 3: Annotation on types in functions *)
Expand Down Expand Up @@ -211,7 +204,7 @@ let f_val : ('a : value). 'a -> 'a = fun x -> f_imm x

type (_ : value) g = MkG : ('a : immediate). 'a g
type t = int as (_ : immediate)
type t = (('a : value), ('b : value)) t2
type t = ('a : value, 'b : value) t2
type ('a, 'b) t = ('a : value) * ('b : value)

class c : object
Expand Down
24 changes: 8 additions & 16 deletions test/passing/tests/layout_annotation.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,20 @@ let f : (_ : immediate) -> (_ : value) = fun _ -> assert false

let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

let f : ((_ : any), _) t = ()
let f : (_ : any, _) t = ()

let g : (_, (_ : any)) t = ()
let g : (_, _ : any) t = ()

let f : ((_ : any), _) t -> t = ()
let f : (_ : any, _) t -> t = ()

let g : (_, (_ : any)) t -> t = ()
let g : (_, _ : any) t -> t = ()

let f :
( _
, (_ : any)
, (_ : any)
, (_ : any)
, (_ : any)
, (_ : any)
, (_ : any)
, (_ : any) )
t
-> t =
(_, _ : any, _ : any, _ : any, _ : any, _ : any, _ : any, _ : any) t -> t
=
()

let g : (_, _, _, _, _, _, _, _, (_ : any)) t -> t = ()
let g : (_, _, _, _, _, _, _, _, _ : any) t -> t = ()

(********************************************)
(* Test 3: Annotation on types in functions *)
Expand Down Expand Up @@ -275,7 +267,7 @@ type (_ : value) g = MkG : ('a : immediate). 'a g

type t = int as (_ : immediate)

type t = (('a : value), ('b : value)) t2
type t = ('a : value, 'b : value) t2

type ('a, 'b) t = ('a : value) * ('b : value)

Expand Down

0 comments on commit 47f3b20

Please sign in to comment.