]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicRefiner.ml
...
[helm.git] / helm / software / components / ng_refiner / nCicRefiner.ml
index 8476119ad081c24489559e5e2e566ea0318f13bb..5a85a1289297301031355cf3bf3dfa4cae83f921 100644 (file)
@@ -993,13 +993,15 @@ let relocalise old_localise dt t add =
 ;;
 
 let undebruijnate inductive ref t rev_fl =
+  let len = List.length rev_fl in 
   NCicSubstitution.psubst (fun x -> x) 
-   (List.rev (HExtlib.list_mapi 
+   (HExtlib.list_mapi 
       (fun (_,_,rno,_,_,_) i -> 
+         let i = len - i - 1 in
          NCic.Const 
            (if inductive then NReference.mk_fix i rno ref
             else NReference.mk_cofix i ref))
-      rev_fl))
+      rev_fl)
     t
 ;; 
 
@@ -1128,6 +1130,29 @@ let typeof_obj
                     metasenv,subst,item1::context
                 ) (metasenv,subst,tys) sx_context_ty_rev sx_context_te_rev
               with Invalid_argument "List.fold_left2" -> assert false in
+             let metasenv, subst =
+                let rec aux context (metasenv,subst) = function
+                  | NCic.Meta _ -> metasenv, subst
+                  | NCic.Implicit _ -> metasenv, subst
+                  | NCic.Appl (NCic.Rel i :: args) as t
+                      when i > List.length context - len ->
+                      let lefts, _ = HExtlib.split_nth leftno args in
+                      let ctxlen = List.length context in
+                      let (metasenv, subst), _ = 
+                        List.fold_left
+                        (fun ((metasenv, subst),l) arg ->
+                          NCicUnification.unify rdb 
+                           ~test_eq_only:true metasenv subst context arg 
+                             (NCic.Rel (ctxlen - len - l)), l+1
+                          )
+                        ((metasenv, subst), 0) lefts
+                      in
+                      metasenv, subst
+                  | t -> NCicUtils.fold (fun e c -> e::c) context aux
+                  (metasenv,subst) t
+                in
+               aux context (metasenv,subst) te
+             in
              let con_sort= NCicTypeChecker.typeof ~subst ~metasenv context te in
               (match
                 NCicReduction.whd ~subst context con_sort,