Skip to content

Commit d860786

Browse files
kim-emgithub-actions[bot]
authored andcommitted
fix: apply? produces a non-synthetic sorry (#8231)
This PR changes the behaviour of `apply?` so that the `sorry` it uses to close the goal is non-synthetic. (Recall that correct use of synthetic sorries requires that the tactic also generates an error message, which we don't want to do in this situation.) Either this PR or #8230 are sufficient to defend against the problem reported in #8212. (cherry picked from commit 77b9e51)
1 parent 583620e commit d860786

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/Lean/Elab/Tactic/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace Lean.Elab
1111
open Meta
1212

1313
/-- Assign `mvarId := sorry` -/
14-
def admitGoal (mvarId : MVarId) : MetaM Unit :=
14+
def admitGoal (mvarId : MVarId) (synthetic : Bool := true): MetaM Unit :=
1515
mvarId.withContext do
1616
let mvarType ← inferType (mkMVar mvarId)
17-
mvarId.assign (← mkLabeledSorry mvarType (synthetic := true) (unique := true))
17+
mvarId.assign (← mkLabeledSorry mvarType (synthetic := synthetic) (unique := true))
1818

1919
def goalsToMessageData (goals : List MVarId) : MessageData :=
2020
MessageData.joinSep (goals.map MessageData.ofGoal) m!"\n\n"

src/Lean/Elab/Tactic/LibrarySearch.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def exact? (ref : Syntax) (required : Option (Array (TSyntax `term))) (requireCl
4848
addExactSuggestion ref (← instantiateMVars (mkMVar mvar)).headBeta
4949
(checkState? := initialState) (addSubgoalsMsg := true) (tacticErrorAsInfo := true)
5050
if suggestions.isEmpty then logError "apply? didn't find any relevant lemmas"
51-
admitGoal goal
51+
admitGoal goal (synthetic := false)
5252

5353
@[builtin_tactic Lean.Parser.Tactic.exact?]
5454
def evalExact : Tactic := fun stx => do

tests/lean/librarySearch.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,7 @@ error: apply? didn't find any relevant lemmas
275275
-/
276276
#guard_msgs in
277277
example {α : Sort u} (x y : α) : Eq x y := by apply?
278+
279+
-- Verify that there is a `sorry` warning when `apply?` closes the goal.
280+
#guard_msgs (drop info) in
281+
example : False := by apply?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
librarySearch.lean:281:0-281:7: warning: declaration uses 'sorry'

0 commit comments

Comments
 (0)