Skip to content

Commit

Permalink
Merge pull request #11396 from gasche/fix11392
Browse files Browse the repository at this point in the history
Fix 11392 (assertion failure on external with -rectypes)

(cherry picked from commit 724cefb)
  • Loading branch information
gasche committed Jul 5, 2022
1 parent 888e843 commit 3979257
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ OCaml 4.14 maintenance branch
of both shadowing warnings and the `-bin-annot` compiler flag.
(Florian Angeletti, report by Christophe Raffalli, review by Gabriel Scherer)

- #11392, #11392: assertion failure with -rectypes and external definitions
(Gabriel Scherer, review by Florian Angeletti, report by Dmitrii Kosarev)

OCaml 4.14.0 (28 March 2022)
----------------------------

Expand Down
34 changes: 34 additions & 0 deletions testsuite/tests/typing-external/pr11392.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(* TEST
* expect
*)

type 'self nat =
| Z
| S of 'self
;;
[%%expect{|
type 'self nat = Z | S of 'self
|}]



(* without rectypes: rejected *)
external cast : int -> 'self nat as 'self = "%identity"
;;
[%%expect{|
Line 1, characters 16-41:
1 | external cast : int -> 'self nat as 'self = "%identity"
^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This alias is bound to type int -> 'a nat
but is used as an instance of type 'a
The type variable 'a occurs inside int -> 'a nat
|}]

#rectypes;;

(* with rectypes: accepted (used to crash) *)
external cast : int -> 'self nat as 'self = "%identity"
;;
[%%expect{|
external cast : int -> 'a nat as 'a = "%identity"
|}]
2 changes: 1 addition & 1 deletion typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ let rec parse_native_repr_attributes env core_type ty ~global_repr =
parse_native_repr_attributes env ct2 t2 ~global_repr
in
(repr_arg :: repr_args, repr_res)
| Ptyp_poly (_, t), _, _ ->
| (Ptyp_poly (_, t) | Ptyp_alias (t, _)), _, _ ->
parse_native_repr_attributes env t ty ~global_repr
| Ptyp_arrow _, _, _ | _, Tarrow _, _ -> assert false
| _ -> ([], make_native_repr env core_type ty ~global_repr)
Expand Down

0 comments on commit 3979257

Please sign in to comment.