Skip to content

Commit

Permalink
Merge PR coq#664: Fixing coq#5500 (missing test in return clause of m…
Browse files Browse the repository at this point in the history
…atch leading to anomaly)
  • Loading branch information
mattam82 committed Jun 14, 2018
2 parents e40e2e7 + f1eac25 commit b5569f5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [ "$CI_PULL_REQUEST" = "664" ] || [ "$CI_BRANCH" = "trunk+fix-5500-too-weak-test-return-clause" ]; then
fiat_parsers_CI_BRANCH=master+change-for-coq-pr664-compatibility
fiat_parsers_CI_GITURL=https://github.com/herbelin/fiat
fi
1 change: 1 addition & 0 deletions pretyping/cases.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ and match_current pb (initial,tomatch) =
let case =
make_case_or_project pb.env !(pb.evdref) indf ci pred current brvals
in
let _ = Typing.e_type_of pb.env pb.evdref pred in
Typing.check_allowed_sort pb.env !(pb.evdref) mind current pred;
{ uj_val = applist (case, inst);
uj_type = prod_applist !(pb.evdref) typ inst }
Expand Down
7 changes: 5 additions & 2 deletions pretyping/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,13 @@ let check_type_fixpoint ?loc env sigma lna lar vdefj =

(* FIXME: might depend on the level of actual parameters!*)
let check_allowed_sort env sigma ind c p =
let pj = Retyping.get_judgment_of env sigma p in
let ksort = Sorts.family (ESorts.kind sigma (sort_of_arity env sigma pj.uj_type)) in
let specif = Global.lookup_inductive (fst ind) in
let sorts = elim_sorts specif in
let pj = Retyping.get_judgment_of env sigma p in
let _, s = splay_prod env sigma pj.uj_type in
let ksort = match EConstr.kind sigma s with
| Sort s -> Sorts.family (ESorts.kind sigma s)
| _ -> error_elim_arity env sigma ind sorts c pj None in
if not (List.exists ((==) ksort) sorts) then
let s = inductive_sort_family (snd specif) in
error_elim_arity env sigma ind sorts c pj
Expand Down
35 changes: 35 additions & 0 deletions test-suite/bugs/closed/5500.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(* Too weak check on the correctness of return clause was leading to an anomaly *)

Inductive Vector A: nat -> Type :=
nil: Vector A O
| cons: forall n, A -> Vector A n -> Vector A (S n).

(* This could be made working with a better inference of inner return
predicates from the return predicate at the higher level of the
nested matching. Currently, we only check that it does not raise an
anomaly, but eventually, the "Fail" could be removed. *)

Fail Definition hd_fst A x n (v: A * Vector A (S n)) :=
match v as v0 return match v0 with
(l, r) =>
match r in Vector _ n return match n with 0 => Type | S _ => Type end with
nil _ => A
| cons _ _ _ _ => A
end
end with
(_, nil _) => x
| (_, cons _ n hd tl) => hd
end.

(* This is another example of failure but involving beta-reduction and
not iota-reduction. Thus, for this one, I don't see how it could be
solved by small inversion, whatever smart is small inversion. *)

Inductive A : (Type->Type) -> Type := J : A (fun x => x).

Fail Check fun x : nat * A (fun x => x) =>
match x return match x with
(y,z) => match z in A f return f Type with J => bool end
end with
(y,J) => true
end.
16 changes: 16 additions & 0 deletions test-suite/bugs/closed/5547.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(* Checking typability of intermediate return predicates in nested pattern-matching *)

Inductive A : (Type->Type) -> Type := J : A (fun x => x).
Definition ret (x : nat * A (fun x => x))
:= match x return Type with
| (y,z) => match z in A f return f Type with
| J => bool
end
end.
Definition foo : forall x, ret x.
Proof.
Fail refine (fun x
=> match x return ret x with
| (y,J) => true
end
).

0 comments on commit b5569f5

Please sign in to comment.