feat: display placeholder & goal errors even on parse error
This commit is contained in:
parent
c09958cf78
commit
60f2faefb7
7 changed files with 35 additions and 5 deletions
|
|
@ -237,7 +237,7 @@ partial def elabCommand (stx : Syntax) : CommandElabM Unit := do
|
|||
if checkTraceOption (← getOptions) `Elab.info then
|
||||
logTrace `Elab.info m!"{← tree.format}"
|
||||
return tree
|
||||
let initMsgs := (← get).messages
|
||||
let initMsgs ← modifyGet fun st => (st.messages, { st with messages := {} })
|
||||
withLogging <| withRef stx <| withInfoTreeContext (mkInfoTree := mkInfoTree) <| withIncRecDepth <| withFreshMacroScope do
|
||||
runLinters stx
|
||||
match stx with
|
||||
|
|
@ -261,10 +261,13 @@ partial def elabCommand (stx : Syntax) : CommandElabM Unit := do
|
|||
| some elabFns => elabCommandUsing s stx elabFns
|
||||
| none => throwError "elaboration function for '{k}' has not been implemented"
|
||||
| _ => throwError "unexpected command"
|
||||
let mut msgs ← (← get).messages
|
||||
-- `stx.hasMissing` should imply `initMsgs.hasErrors`, but the latter should be cheaper to check in general
|
||||
if !showPartialSyntaxErrors.get (← getOptions) && initMsgs.hasErrors && stx.hasMissing then
|
||||
-- discard elaboration errors on parse error
|
||||
modify ({ · with messages := initMsgs})
|
||||
-- discard elaboration errors, except for a few important and unlikely misleading ones, on parse error
|
||||
msgs := ⟨msgs.msgs.filter fun msg =>
|
||||
msg.data.hasTag `Elab.synthPlaceholder || msg.data.hasTag `Tactic.unsolvedGoals⟩
|
||||
modify ({ · with messages := initMsgs ++ msgs })
|
||||
|
||||
/-- Adapt a syntax transformation to a regular, command-producing elaborator. -/
|
||||
def adaptExpander (exp : Syntax → CommandElabM Syntax) : CommandElab := fun stx => do
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ def goalsToMessageData (goals : List MVarId) : MessageData :=
|
|||
|
||||
def Term.reportUnsolvedGoals (goals : List MVarId) : TermElabM Unit :=
|
||||
withPPInaccessibleNames do
|
||||
throwError "unsolved goals\n{goalsToMessageData goals}"
|
||||
throwError MessageData.tagged `Tactic.unsolvedGoals <| m!"unsolved goals\n{goalsToMessageData goals}"
|
||||
|
||||
namespace Tactic
|
||||
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ def MVarErrorInfo.logError (mvarErrorInfo : MVarErrorInfo) (extraMsg? : Option M
|
|||
| MVarErrorKind.hole => do
|
||||
let msg : MessageData := "don't know how to synthesize placeholder"
|
||||
let msg := msg ++ Format.line ++ "context:" ++ Format.line ++ MessageData.ofGoal mvarErrorInfo.mvarId
|
||||
logErrorAt mvarErrorInfo.ref (appendExtra msg)
|
||||
logErrorAt mvarErrorInfo.ref (MessageData.tagged `Elab.synthPlaceholder <| appendExtra msg)
|
||||
| MVarErrorKind.custom msg =>
|
||||
logErrorAt mvarErrorInfo.ref (appendExtra msg)
|
||||
where
|
||||
|
|
|
|||
|
|
@ -77,6 +77,17 @@ where
|
|||
| node msgs => node <| msgs.map (visit . mctx)
|
||||
| _ => msg
|
||||
|
||||
variable (tag : Name) in
|
||||
partial def hasTag : MessageData → Bool
|
||||
| withContext _ msg => hasTag msg
|
||||
| withNamingContext _ msg => hasTag msg
|
||||
| nest _ msg => hasTag msg
|
||||
| group msg => hasTag msg
|
||||
| compose msg₁ msg₂ => hasTag msg₁ || hasTag msg₂
|
||||
| tagged n msg => tag == n || hasTag msg
|
||||
| node msgs => msgs.any hasTag
|
||||
| _ => false
|
||||
|
||||
def nil : MessageData :=
|
||||
ofFormat Format.nil
|
||||
|
||||
|
|
|
|||
2
tests/lean/have.lean
Normal file
2
tests/lean/have.lean
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
example : False :=
|
||||
have False := _
|
||||
4
tests/lean/have.lean.expected.out
Normal file
4
tests/lean/have.lean.expected.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
have.lean:3:0: error: unexpected end of input
|
||||
have.lean:2:16-2:17: error: don't know how to synthesize placeholder
|
||||
context:
|
||||
⊢ False
|
||||
|
|
@ -1,5 +1,15 @@
|
|||
unknownTactic.lean:3:3: error: unknown tactic
|
||||
unknownTactic.lean:1:41-3:8: error: unsolved goals
|
||||
x : Nat
|
||||
a✝ : x = x
|
||||
⊢ x = x
|
||||
---
|
||||
unknownTactic.lean:8:17: error: unknown tactic
|
||||
unknownTactic.lean:8:2-8:19: error: unsolved goals
|
||||
x : Nat
|
||||
⊢ x = x
|
||||
---
|
||||
unknownTactic.lean:14:17: error: unknown tactic
|
||||
unknownTactic.lean:14:2-14:19: error: unsolved goals
|
||||
x : Nat
|
||||
⊢ x = x
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue