fix(library/tactic/destruct_tactic): fixes #1766

This commit is contained in:
Leonardo de Moura 2017-08-02 15:35:33 +01:00
parent fdaa26f2fd
commit f39e42bf2d
3 changed files with 45 additions and 2 deletions

View file

@ -57,10 +57,15 @@ tactic_state destruct(transparency_mode md, expr const & e, tactic_state const &
expr cases;
levels lvls;
if (env.get(name(I_name, "rec")).get_num_univ_params() != length(I_lvls))
if (env.get(name(I_name, "rec")).get_num_univ_params() != length(I_lvls)) {
lvls = cons(target_lvl, I_lvls);
else
} else {
if (!is_zero(target_lvl)) {
throw exception(sstream() << "destruct tactic failed, recursor '" << cases_on_decl.get_name()
<< "' can only eliminate into Prop");
}
lvls = I_lvls;
}
/* cases will contain the cases_on application that we will assing to the main goal */
cases = mk_constant(cases_on_decl.get_name(), lvls);

32
tests/lean/1766.lean Normal file
View file

@ -0,0 +1,32 @@
inductive is_some (x : option nat) : Prop
| mk : ∀ value : nat, x = some value → is_some
def value_1 (x : option nat) (H : is_some x)
: nat :=
begin
destruct x; intros,
{destruct H, -- ERROR: `is_some` can only eliminate into Prop
intros, clear a_2, rw a at a_1, contradiction},
{assumption}
end
def value_2 (x : option nat) (H : is_some x)
: x = x :=
begin
destruct x; intros,
{destruct H,
intros, rw a at a_1},
{refl}
end
inductive is_some' (x : option nat) : Type
| mk : ∀ value : nat, x = some value → is_some'
def value_3 (x : option nat) (H : is_some' x)
: nat :=
begin
destruct x; intros,
{destruct H,
intros, clear a_2, rw a at a_1, contradiction},
{assumption}
end

View file

@ -0,0 +1,6 @@
1766.lean:8:4: error: destruct tactic failed, recursor 'is_some.cases_on' can only eliminate into Prop
state:
x : option ,
H : is_some x,
a : x = none