Skip to content

Commit 0d7f20b

Browse files
committed
check that evar arguments are of the expected type
1 parent 1d7ef24 commit 0d7f20b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clib/sList.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ let rec fold f accu = function
9393
| Cons (x, l) -> fold f (f accu x) l
9494
| Default (_, l) -> fold f accu l
9595

96+
let rec fold_left_map f accu l0 = match l0 with
97+
| Nil -> accu, empty
98+
| Cons (x, l) ->
99+
let accu, x' = f accu x in
100+
let accu, l' = fold_left_map f accu l in
101+
accu, Cons (x', l')
102+
| Default (n, l) ->
103+
let accu, l' = fold_left_map f accu l in
104+
accu, Default (n, l')
105+
96106
let rec for_all f l = match l with
97107
| Nil -> true
98108
| Cons (x, l) -> f x && for_all f l

clib/sList.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ sig
6161
val iter : ('a -> unit) -> 'a t -> unit
6262
val map : ('a -> 'b) -> 'a t -> 'b t
6363
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
64+
val fold_left_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b t -> 'a * 'c t
6465
val for_all : ('a -> bool) -> 'a t -> bool
6566
val exists : ('a -> bool) -> 'a t -> bool
6667

pretyping/typing.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,17 @@ let rec execute env sigma cstr =
532532
match EConstr.kind sigma cstr with
533533
| Meta n -> assert false (* Typing should always be performed on meta-free terms *)
534534

535-
| Evar (_, args as ev) ->
536-
let sigma = SList.Skip.fold (fun sigma x -> fst (execute env sigma x)) sigma args in
535+
| Evar (n, args as ev) ->
536+
let evinfo = Evd.find_undefined sigma n in
537+
let sigma, tys = SList.Skip.fold_left_map (fun sigma x -> execute env sigma x) sigma args in
538+
let atys = Evd.evar_filtered_context evinfo in
539+
let sigma = List.fold_left2 (fun sigma aty ty ->
540+
match ty with | None -> sigma | Some ty ->
541+
let aty = Context.Named.Declaration.get_type aty in
542+
let aty = Evd.instantiate_evar_array sigma evinfo aty args in
543+
Evarconv.unify_leq_delay env sigma ty.uj_type aty
544+
(* FIXME: Find a suitable error msg. *)
545+
) sigma atys (SList.to_list tys) in
537546
let ty = EConstr.existential_type sigma ev in
538547
sigma, { uj_val = cstr; uj_type = ty }
539548

0 commit comments

Comments
 (0)