Skip to content

Commit b5fab27

Browse files
committed
fix: proper error messages for Std.Do tactic invokations without arguments (#11509)
1 parent 05a8124 commit b5fab27

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

src/Std/Tactic/Do/Syntax.lean

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,27 @@ syntax (name := massumption) "massumption" : tactic
7171
@[tactic_alt Lean.Parser.Tactic.mclearMacro]
7272
syntax (name := mclear) "mclear" colGt ident : tactic
7373

74+
@[tactic_alt Lean.Parser.Tactic.mclearMacro]
75+
macro (name := mclearError) "mclear" : tactic => Macro.throwError "`mclear` expects at an identifier"
76+
7477
@[tactic_alt Lean.Parser.Tactic.mconstructorMacro]
7578
syntax (name := mconstructor) "mconstructor" : tactic
7679

7780
@[tactic_alt Lean.Parser.Tactic.mexactMacro]
7881
syntax (name := mexact) "mexact" colGt term : tactic
7982

83+
@[tactic_alt Lean.Parser.Tactic.mexactMacro]
84+
macro (name := mexactError) "mexact" : tactic => Macro.throwError "`mexact` expects a term"
85+
8086
@[tactic_alt Lean.Parser.Tactic.mexfalsoMacro]
8187
syntax (name := mexfalso) "mexfalso" : tactic
8288

8389
@[tactic_alt Lean.Parser.Tactic.mexistsMacro]
8490
syntax (name := mexists) "mexists" term,+ : tactic
8591

92+
@[tactic_alt Lean.Parser.Tactic.mexistsMacro]
93+
macro (name := mexistsError) "mexists" : tactic => Macro.throwError "`mexists` expects at least one term"
94+
8695
@[tactic_alt Lean.Parser.Tactic.mframeMacro]
8796
syntax (name := mframe) "mframe" : tactic
8897

@@ -92,9 +101,15 @@ syntax (name := mdup) "mdup" ident " => " ident : tactic
92101
@[tactic_alt Lean.Parser.Tactic.mhaveMacro]
93102
syntax (name := mhave) "mhave" ident optional(":" term) " := " term : tactic
94103

104+
@[tactic_alt Lean.Parser.Tactic.mhaveMacro]
105+
macro (name := mhaveError) "mhave" : tactic => Macro.throwError "The syntax is `mhave h := term`"
106+
95107
@[tactic_alt Lean.Parser.Tactic.mreplaceMacro]
96108
syntax (name := mreplace) "mreplace" ident optional(":" term) " := " term : tactic
97109

110+
@[tactic_alt Lean.Parser.Tactic.mreplaceMacro]
111+
macro (name := mreplaceError) "mreplace" : tactic => Macro.throwError "The syntax is `mreplace h := term`"
112+
98113
@[tactic_alt Lean.Parser.Tactic.mrightMacro]
99114
syntax (name := mright) "mright" : tactic
100115

@@ -104,18 +119,30 @@ syntax (name := mleft) "mleft" : tactic
104119
@[tactic_alt Lean.Parser.Tactic.mpureMacro]
105120
syntax (name := mpure) "mpure" colGt ident : tactic
106121

122+
@[tactic_alt Lean.Parser.Tactic.mpureMacro]
123+
macro (name := mpureError) "mpure" : tactic => Macro.throwError "`mpure` expects an identifier"
124+
107125
@[tactic_alt Lean.Parser.Tactic.mpureIntroMacro]
108126
syntax (name := mpureIntro) "mpure_intro" : tactic
109127

110128
@[tactic_alt Lean.Parser.Tactic.mrenameIMacro]
111129
syntax (name := mrenameI) "mrename_i" (ppSpace colGt binderIdent)+ : tactic
112130

131+
@[tactic_alt Lean.Parser.Tactic.mrenameIMacro]
132+
macro (name := mrenameIError) "mrename_i" : tactic => Macro.throwError "`mrename_i` expects at least one identifier"
133+
113134
@[tactic_alt Lean.Parser.Tactic.mspecializeMacro]
114135
syntax (name := mspecialize) "mspecialize" ident (colGt term:max)* : tactic
115136

137+
@[tactic_alt Lean.Parser.Tactic.mspecializeMacro]
138+
macro (name := mspecializeError) "mspecialize" : tactic => Macro.throwError "The syntax is `mspecialize h term*`"
139+
116140
@[tactic_alt Lean.Parser.Tactic.mspecializePureMacro]
117141
syntax (name := mspecializePure) "mspecialize_pure" term (colGt term:max)* " => " ident : tactic
118142

143+
@[tactic_alt Lean.Parser.Tactic.mspecializeMacro]
144+
macro (name := mspecializePureError) "mspecialize_pure" : tactic => Macro.throwError "The syntax is `mspecialize_pure h term*`"
145+
119146
@[tactic_alt Lean.Parser.Tactic.mstartMacro]
120147
syntax (name := mstart) "mstart" : tactic
121148

@@ -213,6 +240,9 @@ where
213240
@[tactic_alt Lean.Parser.Tactic.mcasesMacro]
214241
syntax (name := mcases) "mcases" ident " with " mcasesPat : tactic
215242

243+
@[tactic_alt Lean.Parser.Tactic.mcasesMacro]
244+
macro (name := mcasesError) "mcases" : tactic => Macro.throwError "The syntax is `mcases h with pat`"
245+
216246
declare_syntax_cat mrefinePat
217247
syntax binderIdent : mrefinePat
218248
syntax mrefinePats := sepBy1(mrefinePat, ", ")
@@ -250,13 +280,18 @@ where
250280
@[tactic_alt Lean.Parser.Tactic.mrefineMacro]
251281
syntax (name := mrefine) "mrefine" mrefinePat : tactic
252282

283+
@[tactic_alt Lean.Parser.Tactic.mrefineMacro]
284+
macro (name := mrefineError) "mrefine" : tactic => Macro.throwError "`mrefine` expects a pattern"
285+
253286
declare_syntax_cat mintroPat
254287
syntax mcasesPat : mintroPat
255288
syntax "∀" binderIdent : mintroPat
256289

257290
@[tactic_alt Lean.Parser.Tactic.mintroMacro]
258291
syntax (name := mintro) "mintro" (ppSpace colGt mintroPat)+ : tactic
259292

293+
macro (name := mintroError) "mintro" : tactic => Macro.throwError "`mintro` expects at least one pattern"
294+
260295
macro_rules
261296
| `(tactic| mintro $pat₁ $pat₂ $pats:mintroPat*) => `(tactic| mintro $pat₁; mintro $pat₂ $pats*)
262297
| `(tactic| mintro $pat:mintroPat) => do
@@ -272,7 +307,10 @@ syntax ident : mrevertPat
272307
syntax "∀" optional(num) : mrevertPat
273308

274309
@[tactic_alt Lean.Parser.Tactic.mrevertMacro]
275-
syntax (name := mrevert) "mrevert" (ppSpace colGt mrevertPat)+ : tactic
310+
syntax (name := mrevert) "mrevert" (ppSpace colGt mrevertPat)* : tactic
311+
312+
@[tactic_alt Lean.Parser.Tactic.mrevertMacro]
313+
macro (name := mrevertError) "mrevert" : tactic => Macro.throwError "`mrevert` expects at least one pattern"
276314

277315
macro_rules
278316
| `(tactic| mrevert $pat₁ $pat₂ $pats:mrevertPat*) => `(tactic| mrevert $pat₁; mrevert $pat₂ $pats*)

tests/lean/run/11509.lean

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Std.Do
2+
import Std.Tactic.Do
3+
4+
open Std.Do
5+
6+
/-- error: `mclear` expects at an identifier -/
7+
#guard_msgs (error) in
8+
example : True := by mclear
9+
/-- error: `mclear` expects at an identifier -/
10+
#guard_msgs (error) in
11+
example : True := by mclear
12+
/-- error: The syntax is `mhave h := term` -/
13+
#guard_msgs (error) in
14+
example : True := by mhave
15+
/-- error: The syntax is `mreplace h := term` -/
16+
#guard_msgs (error) in
17+
example : True := by mreplace
18+
/-- error: `mpure` expects an identifier -/
19+
#guard_msgs (error) in
20+
example : True := by mpure
21+
/-- error: `mrename_i` expects at least one identifier -/
22+
#guard_msgs (error) in
23+
example : True := by mrename_i
24+
/-- error: The syntax is `mspecialize h term*` -/
25+
#guard_msgs (error) in
26+
example : True := by mspecialize
27+
/-- error: The syntax is `mspecialize_pure h term*` -/
28+
#guard_msgs (error) in
29+
example : True := by mspecialize_pure
30+
/-- error: The syntax is `mcases h with pat` -/
31+
#guard_msgs (error) in
32+
example : True := by mcases
33+
/-- error: `mrefine` expects a pattern -/
34+
#guard_msgs (error) in
35+
example : True := by mrefine
36+
/-- error: `mintro` expects at least one pattern -/
37+
#guard_msgs (error) in
38+
example : True := by mintro
39+
/-- error: `mrevert` expects at least one pattern -/
40+
#guard_msgs (error) in
41+
example : True := by mrevert

0 commit comments

Comments
 (0)