File: pr10294.ml

package info (click to toggle)
js-of-ocaml 6.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (45 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(* TEST *)

type import_error = Node of string
type export_error = Variant of string * string

exception Import of import_error
exception Export of export_error
(* Pattern-matching analysis and compilation considers that two
   exceptions constructors may be equal (one may be a rebinding of
   the other) as long as they have the same arity, as is the case
   here.

   The result of splitting on these two exception constructors is what
   we call an "incoherent row", a pattern matrix whose rows have
   incompatible types (one matching on [import_error], the other on
   [export_error]).

   In the case of the code below, the incoherent row is as follows:

   (Node _)
   (Variant (_, _))

   Note that the two constructors [Node] and [Variant] have different
   arities, but the same tag (0).

   In bug #10924, this causes an assertion-failure in the
   pattern-matching compiler, because a matrix-decomposition
   computation in Default_environment ends up considering that Node
   and Variant are equal, creating a sub-matrix with one wildcard
   pattern in the first row, and two in the second.

   This is fixed by comparing constructors by more than their tags
   (which is insufficient for incoherent rows).
*)
let f = function
  | Import (Node _) ->
      1
  | Export (Variant (_, _)) ->
      2
  | _ ->
      3

let () =
  assert (f (Import (Node "foo")) = 1);
  assert (f (Export (Variant ("foo", "bar"))) = 2);