Debian Codegraph @

test-suite/success/CaseAlias.v

raw
1 (*********************************************)
2 (* This has been a bug reported by Y. Bertot *)
3 Inductive expr : Set :=
4 | b : expr -> expr -> expr
5 | u : expr -> expr
6 | a : expr
7 | var : nat -> expr.
8
9 Fixpoint f (t : expr) : expr :=
10 match t with
11 | b t1 t2 => b (f t1) (f t2)
12 | a => a
13 | x => b t a
14 end.
15
16 Fixpoint f2 (t : expr) : expr :=
17 match t with
18 | b t1 t2 => b (f2 t1) (f2 t2)
19 | a => a
20 | x => b x a
21 end.
22
23 (*********************************************)
24 (* Test expansion of aliases *)
25 (* Originally taken from NMake_gen.v *)
26
27 Local Notation SizePlus n := (S (S (S (S (S (S n)))))).
28 Local Notation Size := (SizePlus O).
29
30 Parameter zn2z : Type -> Type.
31 Parameter w0 : Type.
32 Fixpoint word (w : Type) (n : nat) {struct n} : Type :=
33 match n with
34 | 0 => w
35 | S n0 => zn2z (word w n0)
36 end.
37
38 Definition w1 := zn2z w0.
39 Definition w2 := zn2z w1.
40 Definition w3 := zn2z w2.
41 Definition w4 := zn2z w3.
42 Definition w5 := zn2z w4.
43 Definition w6 := zn2z w5.
44
45 Definition dom_t n := match n with
46 | 0 => w0
47 | 1 => w1
48 | 2 => w2
49 | 3 => w3
50 | 4 => w4
51 | 5 => w5
52 | 6 => w6
53 | SizePlus n => word w6 n
54 end.
55 Parameter plus_t : forall n m : nat, word (dom_t n) m -> dom_t (m + n).
56
57 (* This used to fail because of a bug in expansion of SizePlus wrongly
58 reusing n as an alias for the subpattern *)
59 Definition plus_t1 n : forall m, word (dom_t n) m -> dom_t (m+n) :=
60 match n return (forall m, word (dom_t n) m -> dom_t (m+n)) with
61 | SizePlus (S n') as n => plus_t n
62 | _ as n =>
63 fun m => match m return (word (dom_t n) m -> dom_t (m+n)) with
64 | SizePlus (S (S m')) as m => plus_t n m
65 | _ => fun x => x
66 end
67 end.
68
69 (* Test (useless) intermediate alias *)
70 Definition plus_t2 n : forall m, word (dom_t n) m -> dom_t (m+n) :=
71 match n return (forall m, word (dom_t n) m -> dom_t (m+n)) with
72 | S (S (S (S (S (S (S n'))))) as n) as n'' => plus_t n''
73 | _ as n =>
74 fun m => match m return (word (dom_t n) m -> dom_t (m+n)) with
75 | SizePlus (S (S m')) as m => plus_t n m
76 | _ => fun x => x
77 end
78 end.
79
80 (*****************************************************************************)
81 (* Check that alias expansion behaves consistently from versions to versions *)
82
83 Definition g m :=
84 match pred m with
85 | 0 => 0
86 | n => n (* For compatibility, right-hand side should be (S n), not (pred m) *)
87 end.
88
89 Goal forall m, g m = match pred m with 0 => 0 | S n => S n end.
90 intro; reflexivity.
91 Abort.