Skip to content

Commit cc15988

Browse files
committed
Properly handle is_rec flag, fixing part of issue #117
1 parent 2075b14 commit cc15988

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

src/equations.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,25 +406,25 @@ let define_by_eqs opts eqs nt =
406406
| Struct -> StructuralOn i
407407
| Nested -> NestedOn (Some i)
408408
in
409-
let rec_annot =
409+
let is_rec, rec_annot =
410410
let default_recarg () =
411411
let idx = List.length sign - 1 in
412412
(idx, None)
413413
in
414414
match rec_annot with
415415
| None ->
416416
(match is_rec with
417-
| Some false -> Some (StructuralOn (default_recarg ()))
418-
| _ -> None)
417+
| Some false -> is_rec, Some (StructuralOn (default_recarg ()))
418+
| _ -> is_rec, None)
419419
| Some (reck, None) ->
420420
(match is_recursive i [ieqs] with (* Recursive in its own body? *)
421-
| Some _ -> Some (interp_reca reck (default_recarg ()))
422-
| None -> if reck == Nested then Some (NestedOn None)
423-
else Some (StructuralOn (default_recarg ())))
421+
| Some _ -> Some false, Some (interp_reca reck (default_recarg ()))
422+
| None -> if reck == Nested then is_rec, Some (NestedOn None)
423+
else Some false, Some (StructuralOn (default_recarg ())))
424424
| Some (reck, Some lid) ->
425425
try
426426
let k, _, _ = lookup_rel_id (snd lid) sign in
427-
Some (interp_reca reck (List.length sign - k, Some lid))
427+
Some false, Some (interp_reca reck (List.length sign - k, Some lid))
428428
with Not_found ->
429429
user_err_loc (Some (fst lid), "struct_index",
430430
Pp.(str"No argument named " ++ Id.print (snd lid) ++ str" found"))

test-suite/issues/issue117.v

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From Coq.Lists Require Import List.
2+
From Equations Require Import Equations.
3+
4+
Inductive foo :=
5+
| Sum : list foo -> foo.
6+
7+
Equations (struct t) do_foo1 (t: foo) : nat := {
8+
do_foo1 (Sum u) :=
9+
do_foo1_list2 u }
10+
11+
where (struct ts)
12+
do_foo1_list (ts:list foo) : nat := {
13+
do_foo1_list nil := 0;
14+
do_foo1_list (cons t ts) := 0}
15+
16+
where (struct fs)
17+
do_foo1_list2 (fs : list foo) : nat := {
18+
do_foo1_list2 _ := 0}
19+
20+
where (struct t) do_foo2 (t : foo) : nat := {
21+
do_foo2 _ := 0 }
22+
23+
where (struct ts)
24+
do_foo2_list (ts:list foo) : nat := {
25+
do_foo2_list nil := 0;
26+
do_foo2_list (cons t ts) <= (do_foo2_list ts) => {
27+
do_foo2_list (cons t _) _ := (do_foo1 t) + (do_foo2 t)}}.
28+
29+
Next Obligation. destruct fs; reflexivity. Defined.
30+
Next Obligation. destruct t; reflexivity. Defined.

0 commit comments

Comments
 (0)