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

Use Garrigue's subtyping argument to erase polymorphic variables before performing a toplevel let.

parent 93b36bde
Pipeline #167 passed with stages
in 7 minutes and 36 seconds
......@@ -1560,15 +1560,18 @@ let type_let_decl env p e =
let decl = let_decl env p e in
let typs = type_let_decl env decl in
report_unused_branches ();
List.iter (fun (id, t) ->
let remt = Types.(diff t Function.any) in
let vars = Types.Subst.vars remt in
let typs = List.map
(fun (id, t) ->
let tt = Types.Subst.clean_type Var.Set.empty t in
let vars = Types.Subst.vars tt in
if not (Var.Set.is_empty vars) then
raise_loc_generic p.loc
(Format.asprintf "The type of identifier %a is %a.@\nIt contains polymorphic variables that cannot be generalized."
Ident.print id
Types.Print.print t)
) typs;
Types.Print.print tt);
(id, tt)
) typs
in
let env = enter_values typs env in
({ env with mono_vars = Var.Set.empty; poly_vars = [] }, decl, typs)
......
......@@ -12,7 +12,7 @@ let mmap (f : 'a -> 'b) (l : [ ('a) *] ) : [ ('b) *] =
| (e, ll) -> (f e, mmap f ll)
;;
let map_even = mmap even
let map_even = mmap even in map_even []
;;
let g ( (Int -> Int) -> Int -> Int;
......@@ -37,9 +37,9 @@ max 42;;
let f (_ : ('a | 'b | 'c)) (_ : (Int&'d&'e \1--3 )) : Any = raise "123";;
let e = (even mmap) ;;
let e = (even mmap) in (e (max 4),
let x = id (even (e even));; (* same type as map_even *)
let x = id (even (e even)) in x);; (* same type as map_even *)
/*
The type is below is [ (1--6 | 'a -> 1--6 | 'a)* ]
with weak variables 'a that cannot be safely generlized.
......
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