summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Campbell2019-05-01 15:29:52 +0100
committerBrian Campbell2019-05-06 16:36:45 +0100
commit3cf9fe6ab8779565a3a12d72d401c8f1d9163b90 (patch)
tree92a8cf320454180c7a284e8683daa7331753b1aa /src
parent157935a2394cf900a0e74830f5ea4dc545238c6f (diff)
Cope with irrelevant existentials when monomorphising constructors
Diffstat (limited to 'src')
-rw-r--r--src/monomorphise.ml11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/monomorphise.ml b/src/monomorphise.ml
index fc6d5bfe..b7c6142b 100644
--- a/src/monomorphise.ml
+++ b/src/monomorphise.ml
@@ -392,7 +392,16 @@ let refine_constructor refinements l env id args =
match Type_check.destruct_exist (Type_check.Env.expand_synonyms env constr_ty) with
| None -> None
| Some (kopts,nc,constr_ty) ->
- let bindings = Type_check.unify l env (tyvars_of_typ constr_ty) constr_ty arg_ty in
+ (* Remove existentials in argument types to prevent unification failures *)
+ let unwrap (Typ_aux (t,_) as typ) = match t with
+ | Typ_exist (_,_,typ) -> typ
+ | _ -> typ
+ in
+ let arg_ty = match arg_ty with
+ | Typ_aux (Typ_tup ts,annot) -> Typ_aux (Typ_tup (List.map unwrap ts),annot)
+ | _ -> arg_ty
+ in
+ let bindings = Type_check.unify l env (tyvars_of_typ constr_ty) constr_ty arg_ty in
let find_kopt kopt = try Some (KBindings.find (kopt_kid kopt) bindings) with Not_found -> None in
let bindings = List.map find_kopt kopts in
let matches_refinement (mapping,_,_) =