@@ -1076,9 +1076,12 @@ let tycon_fun_body ?loc env tycon dom =
10761076 let () = unify ?loc env (GTypArrow (dom,codom)) tycon in
10771077 codom
10781078 | GTypRef _ ->
1079- CErrors. user_err ?loc
1080- Pp. (str " This expression should not be a function, the expected type is" ++ spc() ++
1081- pr_glbtype env tycon ++ str " ." )
1079+ let () =
1080+ add_error env ?loc
1081+ Pp. (str " This expression should not be a function, the expected type is" ++ spc() ++
1082+ pr_glbtype env tycon ++ str " ." )
1083+ in
1084+ GTypVar (fresh_id env)
10821085
10831086let tycon_app ?loc env ~ft t =
10841087 match kind env t with
@@ -1093,14 +1096,16 @@ let tycon_app ?loc env ~ft t =
10931096 | GTypArrow _ -> true
10941097 | _ -> false
10951098 in
1096- if is_fun then
1097- CErrors. user_err ?loc
1099+ let () = if is_fun then
1100+ add_error env ?loc
10981101 Pp. (str " This function has type" ++ spc() ++ pr_glbtype env ft ++
10991102 spc() ++ str " and is applied to too many arguments." )
11001103 else
1101- CErrors. user_err ?loc
1104+ add_error env ?loc
11021105 Pp. (str " This expression has type" ++ spc() ++ pr_glbtype env ft ++ str" ." ++
11031106 spc() ++ str " It is not a function and cannot be applied." )
1107+ in
1108+ GTypVar (fresh_id env), GTypVar (fresh_id env)
11041109
11051110let warn_useless_record_with = CWarnings. create ~name: " ltac2-useless-record-with" ~default: AsError
11061111 ~category: CWarnings.CoreCategories. ltac2
@@ -1521,29 +1526,32 @@ and intern_constructor env loc tycon kn args = match kn with
15211526 else
15221527 error_nargs_mismatch ?loc kn nargs (List. length args)
15231528| Tuple n ->
1524- let () = if not (Int. equal n (List. length args)) then begin
1525- if Int. equal 0 n then
1526- (* parsing [() bla] produces [CTacApp (Tuple 0, [bla])] but parsing
1527- [((), ()) bla] produces [CTacApp (CTacApp (Tuple 2, [(); ()]), [bla])]
1528- so we only need to produce a sensible error for [Tuple 0] *)
1529- let t = GTypRef (Tuple 0 , [] ) in
1530- CErrors. user_err ?loc Pp. (
1531- str " This expression has type" ++ spc () ++ pr_glbtype env t ++
1532- spc () ++ str " and is not a function" )
1533- else assert false
1534- end
1535- in
1536- let types = List. init n (fun i -> GTypVar (fresh_id env)) in
1537- let ans = GTypRef (Tuple n, types) in
1538- let ans = match tycon with
1539- | None -> ans
1540- | Some tycon ->
1541- let () = unify ?loc env ans tycon in
1542- tycon
1543- in
1544- let map arg tpe = intern_rec_with_constraint env arg tpe in
1545- let args = List. map2 map args types in
1546- GTacCst (Tuple n, 0 , args), ans
1529+ if not (Int. equal n (List. length args)) then begin
1530+ assert (Int. equal 0 n);
1531+ (* parsing [() bla] produces [CTacApp (Tuple 0, [bla])] but parsing
1532+ [((), ()) bla] produces [CTacApp (CTacApp (Tuple 2, [(); ()]), [bla])]
1533+ so we only need to produce a sensible error for [Tuple 0] *)
1534+ let t = GTypRef (Tuple 0 , [] ) in
1535+ let () =
1536+ add_error env ?loc Pp. (
1537+ str " This expression has type" ++ spc () ++ pr_glbtype env t ++
1538+ spc () ++ str " and is not a function." )
1539+ in
1540+ let args = List. map (fun arg -> fst @@ intern_rec env None arg) args in
1541+ GTacApp (GTacCst (Tuple 0 , 0 , [] ), args), GTypVar (fresh_id env)
1542+ end
1543+ else
1544+ let types = List. init n (fun i -> GTypVar (fresh_id env)) in
1545+ let ans = GTypRef (Tuple n, types) in
1546+ let ans = match tycon with
1547+ | None -> ans
1548+ | Some tycon ->
1549+ let () = unify ?loc env ans tycon in
1550+ tycon
1551+ in
1552+ let map arg tpe = intern_rec_with_constraint env arg tpe in
1553+ let args = List. map2 map args types in
1554+ GTacCst (Tuple n, 0 , args), ans
15471555
15481556and intern_case env loc e tycon pl =
15491557 let e, et = intern_rec env None e in
@@ -1583,6 +1591,17 @@ let intern ~strict ctx e =
15831591 let t = normalize env (count, vars) t in
15841592 (e, (! count, t))
15851593
1594+ let intern_accumulate_errors ~strict ctx e =
1595+ let env = empty_env ~strict ~accumulate_errors: true () in
1596+ (* XXX not doing check_unused_variables *)
1597+ let fold accu (id , t ) = push_name (Name id) (polymorphic t) accu in
1598+ let env = List. fold_left fold env ctx in
1599+ let (e, t) = intern_rec env None e in
1600+ let count = ref 0 in
1601+ let vars = ref TVar.Map. empty in
1602+ let t = normalize env (count, vars) t in
1603+ (e, (! count, t), get_errors env)
1604+
15861605let intern_typedef self (ids , t ) : glb_quant_typedef =
15871606 let env = set_rec self (empty_env () ) in
15881607 (* Initialize type parameters *)
@@ -1776,10 +1795,6 @@ let globalize ids tac =
17761795 in
17771796 globalize_gen ~tacext ids tac
17781797
1779- let debug_globalize_allow_ext ids tac =
1780- let tacext ?loc (RawExt (tag ,arg )) = CAst. make ?loc @@ CTacExt (tag,arg) in
1781- globalize_gen ~tacext ids tac
1782-
17831798let { Goptions. get = typed_notations } =
17841799 Goptions. declare_bool_option_and_ref
17851800 ~key: [" Ltac2" ;" Typed" ;" Notations" ] ~value: true ()
0 commit comments