Skip to content

Commit

Permalink
fix: disable "error to sorry" and "error recovery" at failIfSuccess
Browse files Browse the repository at this point in the history
closes #1375
  • Loading branch information
leodemoura committed Jul 28, 2022
1 parent 888dba8 commit d267b38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Lean/Elab/Tactic/BuiltinTactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ partial def evalChoiceAux (tactics : Array Syntax) (i : Nat) : TacticM Unit :=
@[builtinTactic unknown] def evalUnknown : Tactic := fun stx => do
addCompletionInfo <| CompletionInfo.tactic stx (← getGoals)

@[builtinTactic failIfSuccess] def evalFailIfSuccess : Tactic := fun stx => do
let tactic := stx[1]
if (← try evalTactic tactic; pure true catch _ => pure false) then
throwError "tactic succeeded"
@[builtinTactic failIfSuccess] def evalFailIfSuccess : Tactic := fun stx =>
Term.withoutErrToSorry <| withoutRecover do
let tactic := stx[1]
if (← try evalTactic tactic; pure true catch _ => pure false) then
throwError "tactic succeeded"

@[builtinTactic traceState] def evalTraceState : Tactic := fun _ => do
let gs ← getUnsolvedGoals
Expand Down
7 changes: 5 additions & 2 deletions src/Lean/Elab/Term.lean
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,15 @@ def withAuxDecl (shortDeclName : Name) (type : Expr) (declName : Name) (k : Expr
withReader (fun ctx => { ctx with auxDeclToFullName := ctx.auxDeclToFullName.insert x.fvarId! declName }) do
k x

def withoutErrToSorryImp (x : TermElabM α) : TermElabM α :=
withReader (fun ctx => { ctx with errToSorry := false }) x

/--
Execute `x` without converting errors (i.e., exceptions) to `sorry` applications.
Recall that when `errToSorry = true`, the method `elabTerm` catches exceptions and convert them into `sorry` applications.
-/
def withoutErrToSorry (x : TermElabM α) : TermElabM α :=
withReader (fun ctx => { ctx with errToSorry := false }) x
def withoutErrToSorry [MonadFunctorT TermElabM m] : m α → m α :=
monadMap (m := TermElabM) withoutErrToSorryImp

/-- For testing `TermElabM` methods. The #eval command will sign the error. -/
def throwErrorIfErrors : TermElabM Unit := do
Expand Down
9 changes: 9 additions & 0 deletions tests/lean/run/1375.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
example : True := by
fail_if_success (have : False := by assumption)
trivial

example : True := by
have : False := by
fail_if_success assumption
sorry
trivial

0 comments on commit d267b38

Please sign in to comment.