| C.Lambda (n,s,t) ->
let s',sort1,subst',metasenv',ugraph1 =
- type_of_aux subst metasenv context s ugraph
- in
- (match CicReduction.whd ~subst:subst' context sort1 with
+ type_of_aux subst metasenv context s ugraph in
+ let s',sort1 =
+ match CicReduction.whd ~subst:subst' context sort1 with
C.Meta _
- | C.Sort _ -> ()
- | _ ->
- raise (RefineFailure (lazy (sprintf
- "Not well-typed lambda-abstraction: the source %s should be a type;
- instead it is a term of type %s" (CicPp.ppterm s)
- (CicPp.ppterm sort1))))
- ) ;
+ | C.Sort _ -> s',sort1
+ | coercion_src ->
+ let coercion_tgt = Cic.Sort (Cic.Type (CicUniv.fresh ())) in
+ let search = CoercGraph.look_for_coercion in
+ let boh = search coercion_src coercion_tgt in
+ match boh with
+ | CoercGraph.SomeCoercion c ->
+ Cic.Appl [c;s'], coercion_tgt
+ | CoercGraph.NoCoercion
+ | CoercGraph.NotHandled _
+ | CoercGraph.NotMetaClosed ->
+ raise (RefineFailure (lazy (sprintf
+ "Not well-typed lambda-abstraction: the source %s should be a type; instead it is a term of type %s" (CicPp.ppterm s) (CicPp.ppterm sort1))))
+ in
let context_for_t = ((Some (n,(C.Decl s')))::context) in
let metasenv',t = exp_impl metasenv' subst' context_for_t t in
let t',type2,subst'',metasenv'',ugraph2 =
- type_of_aux subst' metasenv'
- context_for_t t ugraph1
+ type_of_aux subst' metasenv' context_for_t t ugraph1
in
C.Lambda (n,s',t'),C.Prod (n,s',type2),
subst'',metasenv'',ugraph2