lean4-htt/tests/lean/run/2199.lean
Kyle Miller 3878432ac7
fix: make sure local instance detection sees through reductions (#8903)
This PR make sure that the local instance cache calculation applies more
reductions. In #2199 there was an issue where metavariables could
prevent local variables from being considered as local instances. We use
a slightly different approach that ensures that, for example, `let`s at
the ends of telescopes do not cause similar problems. These reductions
were already being calculated, so this does not require any additional
work to be done.

Metaprogramming interface addition: the various forall telescope
functions that do reduction now have a `whnfType` flag (default false).
If it's true, then the callback `k` is given the WHNF of the type. This
is a free operation, since the telescope function already computes it.
2025-06-21 06:26:32 +00:00

44 lines
1.1 KiB
Text

/-!
# Make sure local instance detection can handle metavariables and other reductions
-/
/-!
Reported in https://github.com/leanprover/lean4/issues/2199
The `inferInstance` was failing due to metavariables introduced by `cases`.
-/
theorem exists_foo : ∃ T : Type, Nonempty T := ⟨Unit, ⟨()⟩⟩
example : True := by
cases exists_foo
rename_i T hT
have : Nonempty T := inferInstance
trivial
/-!
The `let` would inhibit `inst` from being seen as a local `Decidable` instance.
Two tests: one where `let` starts a telescope, and another where it's at the end.
(Having `let`s in the middle of a forall telescope always worked.)
-/
axiom p : Nat → Prop
axiom inst : let n := 5; Decidable (p n)
example : True := by
have := inst
have : Decidable (p 5) := inferInstance
trivial
axiom inst' : ∀ k, let n := k; Decidable (p n)
example : True := by
have := inst'
have : Decidable (p 5) := inferInstance
trivial
/-!
This worked before, but here's an extra test that abbreviations are correctly handled.
-/
abbrev D (p : Prop) := Decidable p
example (p : Prop) [D p] : (if p then True else False) ↔ p := by
split <;> simp_all