summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jib/anf.ml5
-rw-r--r--src/type_check.ml10
-rw-r--r--src/type_check.mli2
3 files changed, 12 insertions, 5 deletions
diff --git a/src/jib/anf.ml b/src/jib/anf.ml
index ac25d359..7b91e4a5 100644
--- a/src/jib/anf.ml
+++ b/src/jib/anf.ml
@@ -127,7 +127,7 @@ let rec apat_bindings (AP_aux (apat_aux, _, _)) =
(** This function returns the types of all bound variables in a
pattern. It ignores AP_global, apat_globals is used for that. *)
-let rec apat_types (AP_aux (apat_aux, _, _)) =
+let rec apat_types (AP_aux (apat_aux, env, _)) =
let merge id b1 b2 =
match b1, b2 with
| None, None -> None
@@ -137,7 +137,8 @@ let rec apat_types (AP_aux (apat_aux, _, _)) =
in
match apat_aux with
| AP_tup apats -> List.fold_left (Bindings.merge merge) Bindings.empty (List.map apat_types apats)
- | AP_id (id, typ) -> Bindings.singleton id typ
+ | AP_id (id, typ) when not (is_enum_member id env) -> Bindings.singleton id typ
+ | AP_id _ -> Bindings.empty
| AP_global (id, _) -> Bindings.empty
| AP_app (id, apat, _) -> apat_types apat
| AP_cons (apat1, apat2) -> (Bindings.merge merge) (apat_types apat1) (apat_types apat2)
diff --git a/src/type_check.ml b/src/type_check.ml
index 609e584c..4f0d90bc 100644
--- a/src/type_check.ml
+++ b/src/type_check.ml
@@ -2764,7 +2764,11 @@ let rec filter_casts env from_typ to_typ casts =
type pattern_duplicate =
| Pattern_singleton of l
| Pattern_duplicate of l * l
-
+
+let is_enum_member id env = match Env.lookup_id id env with
+ | Enum _ -> true
+ | _ -> false
+
(* Check if a pattern contains duplicate bindings, and raise a type
error if this is the case *)
let check_pattern_duplicates env pat =
@@ -2779,9 +2783,9 @@ let check_pattern_duplicates env pat =
| duplicate -> duplicate
in
match aux with
- | P_id id ->
+ | P_id id when not (is_enum_member id env) ->
ids := Bindings.update id update_id !ids
- | P_lit _ | P_wild -> ()
+ | P_id _ | P_lit _ | P_wild -> ()
| P_not p | P_as (p, _) | P_typ (_, p) | P_var (p, _) ->
collect_duplicates ids p
| P_or (p1, p2) | P_cons (p1, p2) ->
diff --git a/src/type_check.mli b/src/type_check.mli
index ff839f50..f71f85b3 100644
--- a/src/type_check.mli
+++ b/src/type_check.mli
@@ -341,6 +341,8 @@ val canonicalize : Env.t -> typ -> typ
val subtype_check : Env.t -> typ -> typ -> bool
+val is_enum_member : id -> Env.t -> bool
+
val bind_pat : Env.t -> unit pat -> typ -> tannot pat * Env.t * unit Ast.exp list
(** Variant that doesn't introduce new guards for literal patterns,