Skip to content

Commit

Permalink
Fix crash with module unpack with constraint (#2370)
Browse files Browse the repository at this point in the history
The crash was caused by an Ast rule that is outdated since #2191.
  • Loading branch information
Julow authored Jun 1, 2023
1 parent 1449275 commit ea8f9bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug fixes

- Fix crash due to `module T = (val (x : (module S)))` (#2370, @Julow)
- Fix invalid formatting of `then begin end` (#2369, @Julow)
- Protect match after `fun _ : _ ->` (#2352, @Julow)
- Fix invalid formatting of `(::)` (#2347, @Julow)
Expand Down
10 changes: 1 addition & 9 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1388,15 +1388,7 @@ end = struct
|Pstr_class _ | Pstr_class_type _ | Pstr_include _ | Pstr_attribute _
->
assert false )
| Mod {pmod_desc= Pmod_unpack (e1, _, _); _} -> (
match e1 with
| { pexp_desc=
Pexp_constraint
(e, {ptyp_desc= Ptyp_package _; ptyp_attributes= []; _})
; pexp_attributes= []
; _ } ->
assert (e == exp)
| e -> assert (e == exp) )
| Mod {pmod_desc= Pmod_unpack (e1, _, _); _} -> assert (e1 == exp)
| Cl ctx ->
let rec loop ctx =
match ctx.pcl_desc with
Expand Down
3 changes: 3 additions & 0 deletions test/passing/tests/first_class_module.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ let _ =
let x : (module S) = (module M)
let x = ((module M) : (module S))
let x = (module M : S)

(* Unpack containing a [pexp_constraint]. *)
module T = (val (x : (module S)))
3 changes: 3 additions & 0 deletions test/passing/tests/first_class_module.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ let x : (module S) = (module M)
let x = (module M : S)

let x = (module M : S)

(* Unpack containing a [pexp_constraint]. *)
module T = (val (x : (module S)))

0 comments on commit ea8f9bb

Please sign in to comment.