File tree Expand file tree Collapse file tree 5 files changed +20
-15
lines changed Expand file tree Collapse file tree 5 files changed +20
-15
lines changed Original file line number Diff line number Diff line change @@ -41,8 +41,7 @@ elab_rules : tactic |
41
41
else
42
42
let v := (← instantiateMVars (mkMVar goal)).headBeta
43
43
if trace.isSome then
44
- -- TODO: we should be allowed to pass an identifier to `addHaveSuggestion`.
45
- addHaveSuggestion tk type v
44
+ addHaveSuggestion tk (some name) type v
46
45
let (_, newGoal) ← (← getMainGoal).note name v
47
46
replaceMainGoal [newGoal]
48
47
Original file line number Diff line number Diff line change @@ -113,11 +113,11 @@ only the types of the lemmas in the `using` clause.
113
113
114
114
Suggestions are printed as `have := f a b c`.
115
115
-/
116
- syntax (name := propose') "have?" "!" ? (" : " term)? " using " (colGt term),+ : tactic
116
+ syntax (name := propose') "have?" "!" ? (ident)? ( " : " term)? " using " (colGt term),+ : tactic
117
117
118
118
open Elab.Tactic Elab Tactic in
119
119
elab_rules : tactic
120
- | `(tactic| have ?%$tk $[!%$lucky]? $[ : $type:term]? using $[$terms:term],*) => do
120
+ | `(tactic| have ?%$tk $[!%$lucky]? $[$h:ident]? $[ : $type:term]? using $[$terms:term],*) => do
121
121
let stx ← getRef
122
122
let goal ← getMainGoal
123
123
goal.withContext do
@@ -130,7 +130,7 @@ elab_rules : tactic
130
130
throwError "propose could not find any lemmas using the given hypotheses"
131
131
-- TODO we should have `proposals` return a lazy list, to avoid unnecessary computation here.
132
132
for p in proposals.toList.take 10 do
133
- addHaveSuggestion tk (← inferType p.2 ) p.2 stx
133
+ addHaveSuggestion tk (h.map (·.getId)) ( ← inferType p.2 ) p.2 stx
134
134
if lucky.isSome then
135
135
let mut g := goal
136
136
for p in proposals.toList.take 10 do
Original file line number Diff line number Diff line change @@ -15,21 +15,25 @@ This file could be upstreamed to `Std`.
15
15
open Lean Elab Elab.Tactic PrettyPrinter Meta Std.Tactic.TryThis
16
16
17
17
/-- Add a suggestion for `have : t := e`. -/
18
- def addHaveSuggestion (ref : Syntax) (t? : Option Expr) (e : Expr)
18
+ def addHaveSuggestion (ref : Syntax) (h? : Option Name) ( t? : Option Expr) (e : Expr)
19
19
(origSpan? : Option Syntax := none) : TermElabM Unit := do
20
20
let estx ← delabToRefinableSyntax e
21
21
let prop ← isProp (← inferType e)
22
22
let tac ← if let some t := t? then
23
23
let tstx ← delabToRefinableSyntax t
24
24
if prop then
25
- `(tactic| have : $tstx := $estx)
25
+ match h? with
26
+ | some h => `(tactic| have $(mkIdent h) : $tstx := $estx)
27
+ | none => `(tactic| have : $tstx := $estx)
26
28
else
27
- `(tactic| let this : $tstx := $estx)
29
+ `(tactic| let $(mkIdent (h?.getD `_)) : $tstx := $estx)
28
30
else
29
31
if prop then
30
- `(tactic| have := $estx)
32
+ match h? with
33
+ | some h => `(tactic| have $(mkIdent h) := $estx)
34
+ | none => `(tactic| have := $estx)
31
35
else
32
- `(tactic| let this := $estx)
36
+ `(tactic| let $(mkIdent (h?.getD `_)) := $estx)
33
37
addSuggestion ref tac origSpan?
34
38
35
39
open Lean.Parser.Tactic
Original file line number Diff line number Diff line change 1
1
import Mathlib.Tactic.Observe
2
+ import Std.Tactic.GuardMsgs
2
3
4
+ /-- info: Try this: have h : x + y = y + x := Nat.add_comm x y -/
5
+ #guard_msgs in
3
6
example (x y : Nat) : True := by
4
- observe h : x + y = y + x
7
+ observe? h : x + y = y + x
5
8
guard_hyp h : x + y = y + x
6
9
trivial
Original file line number Diff line number Diff line change @@ -41,16 +41,15 @@ example (K L M : List α) (w : L.Disjoint M) (m : K ⊆ L) : True := by
41
41
42
42
def bar (n : Nat) (x : String) : Nat × String := (n + x.length, x)
43
43
44
- -- FIXME notice a bug here: should not generate `let this✝` with an inaccessible name.
45
44
/--
46
- info: Try this: let this✝ : ℕ × String := bar p.1 p.2
45
+ info: Try this: let a : ℕ × String := bar p.1 p.2
47
46
---
48
- info: Try this: let this✝ : ℕ × String := bar p.1 p.2
47
+ info: Try this: let _ : ℕ × String := bar p.1 p.2
49
48
-/
50
49
#guard_msgs in
51
50
example (p : Nat × String) : True := by
52
51
fail_if_success have ? using p
53
- have ? : Nat × String using p.1 , p.2
52
+ have ? a : Nat × String using p.1 , p.2
54
53
have ? : Nat × _ using p.1 , p.2
55
54
trivial
56
55
You can’t perform that action at this time.
0 commit comments