Commit d3d9dbae authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

Prevent dynamic type checks of polymorphic types.

parent 104b5c84
......@@ -995,16 +995,17 @@ and var env loc s =
with Not_found -> raise_loc loc (UnboundId (id, false)))
and abstraction env loc a =
let vset =
let vset = (* collect all type variables from the interface*)
List.fold_left
(fun acc (t1, t2) -> collect_vars (collect_vars acc t1) t2)
USet.empty a.fun_iface
in
let vset =
let vset = (* remove variables that are locally monomorphic *)
List.fold_left (fun acc (v, _) -> USet.remove v acc) vset env.mono
in
let vset = List.fold_left (fun acc v -> USet.add v acc) vset a.fun_poly in
let all_vars =
(* add those that are explicitely polymorphic. *)
let all_vars =
USet.fold (fun v acc -> (v, Var.mk (U.get_str v)) :: acc) vset env.mono
in
let iface =
......@@ -1215,9 +1216,11 @@ and type_check' loc env e constr precise =
ignore (type_check env e t false);
verify loc t constr
| Check (t0, e, t) ->
if Var.Set.is_empty Types.(Subst.vars (descr t)) then
let te = type_check env e Types.any true in
t0 := Types.cup !t0 te;
verify loc (Types.cap te (Types.descr t)) constr
else error loc "Polymorphic type variables cannot occur in dynamic type-checks"
| Abstraction a ->
let t =
if Types.subtype a.fun_typ constr then a.fun_typ
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment