fix: report error if too many variable names have been provided at induction/cases alternative

This commit is contained in:
Leonardo de Moura 2021-03-08 16:25:02 -08:00
parent 4bbcd305b5
commit ef4ab9c1d1
4 changed files with 14 additions and 1 deletions

View file

@ -210,6 +210,8 @@ def evalAlts (elimInfo : ElimInfo) (alts : Array (Name × MVarId)) (optPreTac :
| some altStx =>
subgoals ← withRef altStx do
let altVarNames := getAltVarNames altStx
if altVarNames.size > numFields then
throwError! "too many variable names provided at alternative '{altName}', #{altVarNames.size} provided, but #{numFields} expected"
let mut (_, altMVarId) ← introN altMVarId numFields altVarNames.toList (useNamesForExplicitOnly := !altHasExplicitModifier altStx)
match (← Cases.unifyEqs numEqs altMVarId {}) with
| none => throwError! "alternative '{altName}' is not needed"

View file

@ -10,7 +10,7 @@ theorem ex1 (m : Nat) : Le m 0 → m = 0 := by
theorem ex2 (m n : Nat) : Le m n → Le m.succ n.succ := by
intro h
induction h with
| base n => apply Le.base
| base => apply Le.base
| succ n m ih =>
apply Le.succ
apply ih

View file

@ -0,0 +1,9 @@
theorem ex1 (n : Nat) : 0 + n = n := by
induction n with
| succ x ih₁ ih₂ ih₃ => admit
| zero => rfl
theorem ex2 (n : Nat) : 0 + n = n := by
cases n with
| succ x ih => admit
| zero => rfl

View file

@ -0,0 +1,2 @@
tooManyVarsAtInduction.lean:3:2-3:31: error: too many variable names provided at alternative 'succ', #4 provided, but #2 expected
tooManyVarsAtInduction.lean:8:2-8:22: error: too many variable names provided at alternative 'succ', #2 provided, but #1 expected