Skip to content

Commit

Permalink
feat: detail error message about invalid mutual blocks
Browse files Browse the repository at this point in the history
Detail error message to prevent user confusion as in this [Zulip
message](https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/Matching.20on.20prop/near/341456011).
Instead of just saying ‘invalid mutual block’, explain what a mutual
block may contain.
  • Loading branch information
odanoburu committed Dec 4, 2023
1 parent 5c2292a commit aa334cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lean/Elab/Declaration.lean
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def elabMutual : CommandElab := fun stx => do
throwErrorAt bad "invalid 'decreasing_by' in 'mutual' block, it must be used after the 'end' keyword"
elabMutualDef stx[1].getArgs hints
else
throwError "invalid mutual block"
throwError "invalid mutual block: either all elements of the block must be inductive declarations, or they must all be definitions/theorems/abbrevs"

/- leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "]" >> many1 ident -/
@[builtin_command_elab «attribute»] def elabAttr : CommandElab := fun stx => do
Expand Down
17 changes: 17 additions & 0 deletions tests/lean/invalidMutualError.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/-! Test invalid mutual block error message -/

inductive Foo : Type where
| foo0 : Nat → Foo
| foo1 : Foo → Foo
| foo2 : Foo → Foo → Foo

mutual

inductive Bar1 : Foo → Prop where
| mk {f : Foo} : Bar f → Bar1 (.foo1 f)

def Bar : Foo → Prop
| .foo1 f => Bar1 f
| _ => True

end
1 change: 1 addition & 0 deletions tests/lean/invalidMutualError.lean.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalidMutualError.lean:8:0-17:3: error: invalid mutual block: either all elements of the block must be inductive declarations, or they must all be definitions/theorems/abbrevs

0 comments on commit aa334cb

Please sign in to comment.