Skip to content

Commit

Permalink
Fix ocaml#8575: Surprising interaction between polymorphic variants a…
Browse files Browse the repository at this point in the history
…nd constructor disambiguation
  • Loading branch information
garrigue committed Apr 21, 2021
1 parent 787624a commit 505ee06
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ Working version
when the systhreads library is loaded.
(David Allsopp, report by Anton Bachin, review by Xavier Leroy)

- #8575: Surprising interaction between polymorphic variants and constructor
disambiguation.
(Jacques Garrigue, report by Thomas Refis)

- #9936: Make sure that `List.([1;2;3])` is printed `[1;2;3]` in the toplevel
by identifying lists by their types.
(Florian Angeletti, review by Gabriel Scherer)
Expand Down
36 changes: 36 additions & 0 deletions testsuite/tests/typing-polyvariants-bugs/pr8575.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(* TEST
* expect
*)

module A = struct type t = A | B let x = B end;;
[%%expect{|
module A : sig type t = A | B val x : t end
|}]

let test () =
match A.x with
| A as a -> `A_t a
| B when false -> `Onoes
| B -> if Random.bool () then `Onoes else `A_t B;;
[%%expect{|
val test : unit -> [> `A_t of A.t | `Onoes ] = <fun>
|}, Principal{|
Line 5, characters 49-50:
5 | | B -> if Random.bool () then `Onoes else `A_t B;;
^
Error: Unbound constructor B
|}]

let test () =
match A.x with
| B when false -> `Onoes
| A as a -> `A_t a
| B -> if Random.bool () then `Onoes else `A_t B;;
[%%expect{|
val test : unit -> [> `A_t of A.t | `Onoes ] = <fun>
|}, Principal{|
Line 5, characters 49-50:
5 | | B -> if Random.bool () then `Onoes else `A_t B;;
^
Error: Unbound constructor B
|}]
2 changes: 1 addition & 1 deletion typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3008,7 +3008,7 @@ and type_expect_
begin try match
sarg, expand_head env ty_expected, expand_head env ty_expected0 with
| Some sarg, {desc = Tvariant row}, {desc = Tvariant row0} ->
let row = row_repr row in
let row = row_repr row and row0 = row_repr row0 in
begin match row_field_repr (List.assoc l row.row_fields),
row_field_repr (List.assoc l row0.row_fields) with
Rpresent (Some ty), Rpresent (Some ty0) ->
Expand Down

0 comments on commit 505ee06

Please sign in to comment.