Skip to content

Commit b5569f5

Browse files
committed
Merge PR rocq-prover#664: Fixing rocq-prover#5500 (missing test in return clause of match leading to anomaly)
2 parents e40e2e7 + f1eac25 commit b5569f5

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if [ "$CI_PULL_REQUEST" = "664" ] || [ "$CI_BRANCH" = "trunk+fix-5500-too-weak-test-return-clause" ]; then
2+
fiat_parsers_CI_BRANCH=master+change-for-coq-pr664-compatibility
3+
fiat_parsers_CI_GITURL=https://github.com/herbelin/fiat
4+
fi

pretyping/cases.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ and match_current pb (initial,tomatch) =
14271427
let case =
14281428
make_case_or_project pb.env !(pb.evdref) indf ci pred current brvals
14291429
in
1430+
let _ = Typing.e_type_of pb.env pb.evdref pred in
14301431
Typing.check_allowed_sort pb.env !(pb.evdref) mind current pred;
14311432
{ uj_val = applist (case, inst);
14321433
uj_type = prod_applist !(pb.evdref) typ inst }

pretyping/typing.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,13 @@ let check_type_fixpoint ?loc env sigma lna lar vdefj =
197197

198198
(* FIXME: might depend on the level of actual parameters!*)
199199
let check_allowed_sort env sigma ind c p =
200-
let pj = Retyping.get_judgment_of env sigma p in
201-
let ksort = Sorts.family (ESorts.kind sigma (sort_of_arity env sigma pj.uj_type)) in
202200
let specif = Global.lookup_inductive (fst ind) in
203201
let sorts = elim_sorts specif in
202+
let pj = Retyping.get_judgment_of env sigma p in
203+
let _, s = splay_prod env sigma pj.uj_type in
204+
let ksort = match EConstr.kind sigma s with
205+
| Sort s -> Sorts.family (ESorts.kind sigma s)
206+
| _ -> error_elim_arity env sigma ind sorts c pj None in
204207
if not (List.exists ((==) ksort) sorts) then
205208
let s = inductive_sort_family (snd specif) in
206209
error_elim_arity env sigma ind sorts c pj

test-suite/bugs/closed/5500.v

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(* Too weak check on the correctness of return clause was leading to an anomaly *)
2+
3+
Inductive Vector A: nat -> Type :=
4+
nil: Vector A O
5+
| cons: forall n, A -> Vector A n -> Vector A (S n).
6+
7+
(* This could be made working with a better inference of inner return
8+
predicates from the return predicate at the higher level of the
9+
nested matching. Currently, we only check that it does not raise an
10+
anomaly, but eventually, the "Fail" could be removed. *)
11+
12+
Fail Definition hd_fst A x n (v: A * Vector A (S n)) :=
13+
match v as v0 return match v0 with
14+
(l, r) =>
15+
match r in Vector _ n return match n with 0 => Type | S _ => Type end with
16+
nil _ => A
17+
| cons _ _ _ _ => A
18+
end
19+
end with
20+
(_, nil _) => x
21+
| (_, cons _ n hd tl) => hd
22+
end.
23+
24+
(* This is another example of failure but involving beta-reduction and
25+
not iota-reduction. Thus, for this one, I don't see how it could be
26+
solved by small inversion, whatever smart is small inversion. *)
27+
28+
Inductive A : (Type->Type) -> Type := J : A (fun x => x).
29+
30+
Fail Check fun x : nat * A (fun x => x) =>
31+
match x return match x with
32+
(y,z) => match z in A f return f Type with J => bool end
33+
end with
34+
(y,J) => true
35+
end.

test-suite/bugs/closed/5547.v

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(* Checking typability of intermediate return predicates in nested pattern-matching *)
2+
3+
Inductive A : (Type->Type) -> Type := J : A (fun x => x).
4+
Definition ret (x : nat * A (fun x => x))
5+
:= match x return Type with
6+
| (y,z) => match z in A f return f Type with
7+
| J => bool
8+
end
9+
end.
10+
Definition foo : forall x, ret x.
11+
Proof.
12+
Fail refine (fun x
13+
=> match x return ret x with
14+
| (y,J) => true
15+
end
16+
).

0 commit comments

Comments
 (0)