diff options
| author | Hugo Herbelin | 2020-04-13 00:50:06 +0200 |
|---|---|---|
| committer | Hugo Herbelin | 2020-12-09 11:04:47 +0100 |
| commit | c8c93bfea6e3c75ebce256f44043a34fe8933b5e (patch) | |
| tree | 264633478d3dff7b3777f57311024aad83090237 /pretyping/cases.ml | |
| parent | 3f286f3fcb846cac360969372d71e91c5aefe810 (diff) | |
Fixing support for argument scopes and let-ins while interning cases patterns.
We also simplify the whole process of interpretation of cases pattern
on the way.
Diffstat (limited to 'pretyping/cases.ml')
| -rw-r--r-- | pretyping/cases.ml | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/pretyping/cases.ml b/pretyping/cases.ml index a793e217d4..14417d15c6 100644 --- a/pretyping/cases.ml +++ b/pretyping/cases.ml @@ -46,8 +46,8 @@ module NamedDecl = Context.Named.Declaration type pattern_matching_error = | BadPattern of constructor * constr | BadConstructor of constructor * inductive - | WrongNumargConstructor of constructor * int - | WrongNumargInductive of inductive * int + | WrongNumargConstructor of constructor * bool * int * int * int + | WrongNumargInductive of inductive * bool * int * int * int | UnusedClause of cases_pattern list | NonExhaustive of cases_pattern list | CannotInferPredicate of (constr * types) array @@ -65,11 +65,11 @@ let error_bad_constructor ?loc env cstr ind = raise_pattern_matching_error ?loc (env, Evd.empty, BadConstructor (cstr,ind)) -let error_wrong_numarg_constructor ?loc env c n = - raise_pattern_matching_error ?loc (env, Evd.empty, WrongNumargConstructor(c,n)) +let error_wrong_numarg_constructor ?loc env c expanded n n1 n2 = + raise_pattern_matching_error ?loc (env, Evd.empty, WrongNumargConstructor(c,expanded,n,n1,n2)) -let error_wrong_numarg_inductive ?loc env c n = - raise_pattern_matching_error ?loc (env, Evd.empty, WrongNumargInductive(c,n)) +let error_wrong_numarg_inductive ?loc env c expanded n n1 n2 = + raise_pattern_matching_error ?loc (env, Evd.empty, WrongNumargInductive(c,expanded,n,n1,n2)) let list_try_compile f l = let rec aux errors = function @@ -519,13 +519,17 @@ let check_and_adjust_constructor env ind cstrs pat = match DAst.get pat with (* Check the constructor has the right number of args *) let ci = cstrs.(i-1) in let nb_args_constr = ci.cs_nargs in - if Int.equal (List.length args) nb_args_constr then pat + let nargs = List.length args in + if Int.equal nargs nb_args_constr then pat else try let args' = adjust_local_defs ?loc (args, List.rev ci.cs_args) in DAst.make ?loc @@ PatCstr (cstr, args', alias) with NotAdjustable -> - error_wrong_numarg_constructor ?loc env cstr nb_args_constr + let nlet = List.count (function LocalDef _ -> true | _ -> false) ci.cs_args in + (* In practice, this is already checked at interning *) + error_wrong_numarg_constructor ?loc env cstr + (* as if not expanded: *) false nargs nb_args_constr (nb_args_constr + nlet) else (* Try to insert a coercion *) try |
