Skip to content

Commit

Permalink
fix: make @[elab_as_elim] require at least one discriminant (#5671)
Browse files Browse the repository at this point in the history
This is an oversight in `getElabElimExprInfo`. If there are no
discriminants, then there is no point in elaborating as an eliminator.
  • Loading branch information
kmill authored Oct 10, 2024
1 parent 3930100 commit 4614b75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lean/Elab/App.lean
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def getElabElimExprInfo (elimExpr : Expr) : MetaM ElabElimInfo := do
forallTelescopeReducing elimType fun xs type => do
let motive := type.getAppFn
let motiveArgs := type.getAppArgs
unless motive.isFVar do
unless motive.isFVar && motiveArgs.size > 0 do
throwError "unexpected eliminator resulting type{indentExpr type}"
let motiveType ← inferType motive
forallTelescopeReducing motiveType fun motiveParams motiveResultType => do
Expand Down
12 changes: 12 additions & 0 deletions tests/lean/run/elabAsElim.lean
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ In this example, `h0` and `h1` used to be reversed, leading to a kernel typechec
-/
example (n : Nat) (h0 : n ≠ 0) (h1 : n ≠ 1) : n - 2 ≠ n - 1 :=
Nat.recOn n (by simp) (by rintro (_ | _) <;> simp) h0 h1

/-!
Check that eliminators need at least one discriminant
-/

/--
error: unexpected eliminator resulting type
p
-/
#guard_msgs in
@[elab_as_elim]
theorem mySillyEliminator {p : Prop} (h : p) : p := h

0 comments on commit 4614b75

Please sign in to comment.