Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVarId.assertAfter incorrectly upgrades recursive auxDecl to kind "default". #1963

Closed
dwrensha opened this issue Dec 17, 2022 · 1 comment · Fixed by #1968
Closed

MVarId.assertAfter incorrectly upgrades recursive auxDecl to kind "default". #1963

dwrensha opened this issue Dec 17, 2022 · 1 comment · Fixed by #1968

Comments

@dwrensha
Copy link
Contributor

import Lean

open Lean Elab.Tactic Lean.Meta

syntax (name := assertTrival) "assert_trivial ": tactic

elab_rules : tactic
  | `(tactic| assert_trivial) => withMainContext do
  let fvarIds := (← getLCtx).getFVarIds
  guard (fvarIds.size > 0)
  let fvarId := fvarIds[0]!
  let ty ← elabTerm (← `(True)) none
  let e ← elabTerm (← `(True.intro)) none
  let _ ← liftMetaTactic fun mvarId =>  do
     let result ← mvarId.assertAfter fvarId (Name.mkSimple "inserted_by_assert_trivial") ty e
     pure [result.mvarId]
  pure ()

variable {p : Prop}

theorem foo : p :=
by assert_trivial
   sorry

/-
  at the `sorry`, the context is:

    p : Prop
    inserted_by_assert_trivial : True
    foo : p
    ⊢ p

That `foo` hypothesis should not be there.
-/
$ lean --version
Lean (version 4.0.0-nightly-2022-12-13, commit 88c8cd5cf29a, Release)
@dwrensha
Copy link
Contributor Author

We hit this behavior in mathlib4: leanprover-community/mathlib4#1061

@dwrensha dwrensha changed the title MVarId.assertAfter incorrectly adds auxDecls to context MVarId.assertAfter incorrectly upgrades recursive auxDecl to kind "default". Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant