Closes #5634. Before assigning the simplified `using` clause expression to the goal, this adds a check that the expression has no new metavariables. It also adjusts how new hypotheses are added to the goal to prevent spurious "don't know how to synthesize placeholder" errors on that goal metavariable. We also throw in an occurs check immediately after elaboration to avoid some counterintuitive behavior when simplifying such a term closes the goal. Closes #4101. This also improves the type mismatch error message, showing the elaborated `using` clause rather than `h✝`: ```lean example : False := by simpa using (fun x : True => x) /- error: type mismatch, term fun x => x after simplification has type True : Prop but is expected to have type False : Prop -/ ```
50 lines
1.5 KiB
Text
50 lines
1.5 KiB
Text
def Vect (n: Nat) (A: Type u) := {l: List A // l.length = n}
|
|
|
|
def Vect.cons (a: A) (v: Vect n A): Vect (n + 1) A :=
|
|
⟨a::v.val, by simp [v.property]⟩
|
|
|
|
instance: GetElem (Vect n A) Nat A (λ _ i => i < n) where
|
|
getElem vec i _ := match vec with | ⟨l, _⟩ => l[i]
|
|
|
|
set_option pp.mvars false
|
|
/--
|
|
error: type mismatch
|
|
xm[i]
|
|
has type
|
|
Vect m A : outParam (Type _)
|
|
but is expected to have type
|
|
A : outParam (Type _)
|
|
---
|
|
error: type mismatch, term
|
|
ih
|
|
after simplification has type
|
|
i < as.length : Prop
|
|
but is expected to have type
|
|
?_ : Type _
|
|
---
|
|
error: failed to prove index is valid, possible solutions:
|
|
- Use `have`-expressions to prove the index is valid
|
|
- Use `a[i]!` notation instead, runtime check is performed, and 'Panic' error message is produced if index is not valid
|
|
- Use `a[i]?` notation instead, result is an `Option` type
|
|
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid
|
|
A : Type _
|
|
m i j : Nat
|
|
as : List A
|
|
xm : List (Vect m A)
|
|
h0 : xm.length = as.length
|
|
ih : i < (List.zipWith cons as xm).length
|
|
jh : j < m
|
|
⊢ ?_ (sorryAx ?_ true) j
|
|
-/
|
|
#guard_msgs in
|
|
theorem Vect.aux
|
|
{as: List A} {xm: List (Vect m A)}
|
|
(h0: xm.length = as.length)
|
|
(ih: i < (List.zipWith cons as xm).length)
|
|
(jh: j < m)
|
|
: ((List.zipWith cons as xm)[i])[j + 1] =
|
|
xm[i]'(by simpa[h0] using ih)[j] := by
|
|
-- Correct syntax requires an extra pair of parentheses:
|
|
-- (xm[i]'(by simpa[h0] using ih))[j]
|
|
-- but `lean` should not crash.
|
|
sorry
|