Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Aug 5, 2022
1 parent 9cbd815 commit 052a597
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 86 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- Fix indentation when ocamlformat is disabled on an expression (#2129, @gpetiot)
- Reset max-indent when the `max-indent` option is not set (#2131, @hhugo, @gpetiot)

### Changes

- Preserve syntax of module unpack with type constraint (`((module X) : (module Y))` vs `(module X : Y)`) (#2136, @trefis, @gpetiot)

## 0.24.1 (2022-07-18)

### New features
Expand Down
6 changes: 2 additions & 4 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ end = struct
match ctx.ppat_desc with
| Ppat_constraint (_, t1) -> assert (typ == t1)
| Ppat_extension (_, PTyp t) -> assert (typ == t)
| Ppat_unpack (_, Some (_, l)) ->
assert (List.exists l ~f:(fun (_, t) -> typ == t))
| _ -> assert false )
| Exp ctx -> (
match ctx.pexp_desc with
Expand Down Expand Up @@ -1999,10 +2001,6 @@ end = struct
| Str {pstr_desc= Pstr_value _; _} )
, Ppat_constraint ({ppat_desc= Ppat_tuple _; _}, _) ) ->
false
| ( ( Exp {pexp_desc= Pexp_let _ | Pexp_letop _; _}
| Str {pstr_desc= Pstr_value _; _} )
, Ppat_constraint _ ) ->
true
| _, Ppat_constraint _
|_, Ppat_unpack _
|( Pat
Expand Down
47 changes: 16 additions & 31 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,6 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false)
~after:lid1.loc ;
let typ = sub_typ ~ctx:(Pat pat) t in
Cmts.fmt c ppat_loc @@ fmt_record_field c ~typ lid1
| Ppat_constraint ({ppat_desc= Ppat_unpack _; ppat_loc; _}, _) ->
Cmts.fmt c ppat_loc
@@ fmt_record_field c ~rhs:(fmt_rhs ~ctx pat) lid1
| Ppat_constraint (p, t) when List.is_empty ppat_attributes ->
let typ = sub_typ ~ctx:(Pat pat) t
and rhs = fmt_rhs ~ctx:(Pat pat) p in
Expand Down Expand Up @@ -1171,24 +1168,21 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false)
$ fmt_or_k nested
(fits_breaks (if parens then ")" else "") "")
(fits_breaks (if parens then ")" else "") ~hint:(1, 2) ")") )
| Ppat_constraint
( {ppat_desc= Ppat_unpack name; ppat_attributes= []; ppat_loc; _}
, ( { ptyp_desc= Ptyp_package (id, cnstrs)
; ptyp_attributes= []
; ptyp_loc= (* TODO: use ptyp_loc *) _
; _ } as typ ) ) ->
let ctx = Typ typ in
hovbox 0
(Params.parens_if parens c.conf
(hvbox 1
(Cmts.fmt c typ.ptyp_loc
( hovbox 0
( Cmts.fmt c ppat_loc
( str "module"
$ fmt_extension_suffix c ext
$ char ' ' $ fmt_str_loc_opt c name )
$ fmt "@ : " $ fmt_longident_loc c id )
$ fmt_package_type c ctx cnstrs ) ) ) )
| Ppat_unpack (name, pt) ->
let fmt_constraint_opt pt k =
match pt with
| Some (id, cnstrs) ->
hovbox 0
(Params.parens_if parens c.conf
(hvbox 1
( hovbox 0 (k $ fmt "@ : " $ fmt_longident_loc c id)
$ fmt_package_type c ctx cnstrs ) ) )
| None -> wrap_fits_breaks_if ~space:false c.conf parens "(" ")" k
in
fmt_constraint_opt pt
( str "module"
$ fmt_extension_suffix c ext
$ char ' ' $ fmt_str_loc_opt c name )
| Ppat_constraint (pat, typ) ->
hvbox 2
(Params.parens_if parens c.conf
Expand All @@ -1205,11 +1199,6 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false)
$ fmt_extension_suffix c ext
$ fmt "@ "
$ fmt_pattern c (sub_pat ~ctx pat) ) )
| Ppat_unpack name ->
wrap_fits_breaks_if ~space:false c.conf parens "(" ")"
( str "module"
$ fmt_extension_suffix c ext
$ fmt "@ " $ fmt_str_loc_opt c name )
| Ppat_exception pat ->
cbox 2
(Params.parens_if parens c.conf
Expand All @@ -1220,11 +1209,7 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false)
| Ppat_extension
( ext
, PPat
( ( { ppat_desc=
( Ppat_lazy _ | Ppat_unpack _ | Ppat_exception _
| Ppat_constraint
( {ppat_desc= Ppat_unpack _; _}
, {ptyp_desc= Ptyp_package _; _} ) )
( ( { ppat_desc= Ppat_lazy _ | Ppat_unpack _ | Ppat_exception _
; ppat_loc
; ppat_attributes= []
; _ } as pat )
Expand Down
2 changes: 2 additions & 0 deletions test/passing/tests/js_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4325,11 +4325,13 @@ module M' = M
module B' = B

class b : B.a = object
method a : 'a. 'a M.s -> 'a = fun (type a) (module X : M.S with type a = a) -> X.v
method a : 'a. 'a M.s -> 'a = fun (type a) ((module X) : (module M.S with type
a = a)) -> X.v
end

class b' : B.a = object
method a : 'a. 'a M'.s -> 'a = fun (type a) (module X : M'.S with type a = a) -> X.v
method a : 'a. 'a M'.s -> 'a = fun (type a) ((module X) : (module M'.S with
type a = a)) -> X.v
end
Expand Down
10 changes: 5 additions & 5 deletions test/passing/tests/js_source.ml.err
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Warning: tests/js_source.ml:157 exceeds the margin
Warning: tests/js_source.ml:3559 exceeds the margin
Warning: tests/js_source.ml:9541 exceeds the margin
Warning: tests/js_source.ml:9644 exceeds the margin
Warning: tests/js_source.ml:9663 exceeds the margin
Warning: tests/js_source.ml:9703 exceeds the margin
Warning: tests/js_source.ml:9785 exceeds the margin
Warning: tests/js_source.ml:9547 exceeds the margin
Warning: tests/js_source.ml:9650 exceeds the margin
Warning: tests/js_source.ml:9669 exceeds the margin
Warning: tests/js_source.ml:9709 exceeds the margin
Warning: tests/js_source.ml:9791 exceeds the margin
6 changes: 6 additions & 0 deletions test/passing/tests/js_source.ml.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -5050,11 +5050,17 @@ module B' = B
class b : B.a =
object
method a : 'a. 'a M.s -> 'a = fun (type a) (module X : M.S with type a = a) -> X.v

method a : 'a. 'a M.s -> 'a =
fun (type a) ((module X) : (module M.S with type a = a)) -> X.v
end

class b' : B.a =
object
method a : 'a. 'a M'.s -> 'a = fun (type a) (module X : M'.S with type a = a) -> X.v

method a : 'a. 'a M'.s -> 'a =
fun (type a) ((module X) : (module M'.S with type a = a)) -> X.v
end

module type FOO = sig
Expand Down
6 changes: 6 additions & 0 deletions test/passing/tests/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -5050,11 +5050,17 @@ module B' = B
class b : B.a =
object
method a : 'a. 'a M.s -> 'a = fun (type a) (module X : M.S with type a = a) -> X.v

method a : 'a. 'a M.s -> 'a =
fun (type a) ((module X) : (module M.S with type a = a)) -> X.v
end

class b' : B.a =
object
method a : 'a. 'a M'.s -> 'a = fun (type a) (module X : M'.S with type a = a) -> X.v

method a : 'a. 'a M'.s -> 'a =
fun (type a) ((module X) : (module M'.S with type a = a)) -> X.v
end

module type FOO = sig
Expand Down
2 changes: 2 additions & 0 deletions test/passing/tests/source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4325,11 +4325,13 @@ module M' = M
module B' = B

class b : B.a = object
method a : 'a. 'a M.s -> 'a = fun (type a) (module X : M.S with type a = a) -> X.v
method a : 'a. 'a M.s -> 'a = fun (type a) ((module X) : (module M.S with type
a = a)) -> X.v
end

class b' : B.a = object
method a : 'a. 'a M'.s -> 'a = fun (type a) (module X : M'.S with type a = a) -> X.v
method a : 'a. 'a M'.s -> 'a = fun (type a) ((module X) : (module M'.S with
type a = a)) -> X.v
end
Expand Down
6 changes: 6 additions & 0 deletions test/passing/tests/source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -4808,12 +4808,18 @@ class b : B.a =
object
method a : 'a. 'a M.s -> 'a =
fun (type a) (module X : M.S with type a = a) -> X.v

method a : 'a. 'a M.s -> 'a =
fun (type a) ((module X) : (module M.S with type a = a)) -> X.v
end

class b' : B.a =
object
method a : 'a. 'a M'.s -> 'a =
fun (type a) (module X : M'.S with type a = a) -> X.v

method a : 'a. 'a M'.s -> 'a =
fun (type a) ((module X) : (module M'.S with type a = a)) -> X.v
end

module type FOO = sig
Expand Down
6 changes: 3 additions & 3 deletions vendor/diff-parsers-ext-parsewyc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
{ Pexp_new($3), $2 }
| LPAREN MODULE ext_attributes module_expr RPAREN
{ Pexp_pack $4, $3 }
| LPAREN MODULE ext_attributes module_expr COLON package_type RPAREN
| LPAREN MODULE ext_attributes module_expr COLON package_core_type RPAREN
{ Pexp_constraint (ghexp ~loc:$sloc (Pexp_pack $4), $6), $3 }
- | LPAREN MODULE ext_attributes module_expr COLON error
- { unclosed "(" $loc($1) ")" $loc($6) }
Expand Down Expand Up @@ -667,7 +667,7 @@
- LBRACKET expr_semi_list error
- { unclosed "[" $loc($3) "]" $loc($5) }
| od=open_dot_declaration DOT LPAREN MODULE ext_attributes module_expr COLON
package_type RPAREN
package_core_type RPAREN
{ let modexp =
mkexp_attrs ~loc:($startpos($3), $endpos)
(Pexp_constraint (ghexp ~loc:$sloc (Pexp_pack $6), $8)) $5 in
Expand Down Expand Up @@ -758,7 +758,7 @@
- { unclosed "(" $loc($1) ")" $loc($5) }
- | LPAREN pattern COLON error
- { expecting $loc($4) "type" }
- | LPAREN MODULE ext_attributes module_name COLON package_type
- | LPAREN MODULE ext_attributes module_name COLON package_core_type
- error
- { unclosed "(" $loc($1) ")" $loc($7) }
| extension
Expand Down
Loading

0 comments on commit 052a597

Please sign in to comment.