lean4-htt/tests/lean/run/2058.lean
Kyle Miller 68c006a95b
feat: transform nondependent lets into haves in declarations and equation lemmas (#8373)
This PR enables transforming nondependent `let`s into `have`s in a
number of contexts: the bodies of nonrecursive definitions, equation
lemmas, smart unfolding definitions, and types of theorems. A motivation
for this change is that when zeta reduction is disabled, `simp` can only
effectively rewrite `have` expressions (e.g. `split` uses `simp` with
zeta reduction disabled), and so we cache the nondependence calculations
by transforming `let`s to `have`s. The transformation can be disabled
using `set_option cleanup.letToHave false`.

Uses `Meta.letToHave`, introduced in #8954.
2025-06-29 19:45:45 +00:00

87 lines
1.8 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-!
# Localized error messages with unassigned metavariables
-/
set_option pp.mvars false
/-!
Test: now reports "don't know how to synthesize implicit argument" rather than an error on the `example` command.
-/
/--
error: don't know how to synthesize implicit argument 'α'
@none ?_
context:
⊢ Type _
---
error: failed to infer 'let' declaration type
-/
#guard_msgs in
example : IO Unit := do
let x := none
pure ()
/-!
Test: now reports that the universe levels are not assigned at the 'let' rather than an error on the `example` command.
-/
/--
error: failed to infer universe levels in 'let' declaration type
PUnit.{_}
-/
#guard_msgs in
def foo : IO Unit := do
let x : PUnit := PUnit.unit
pure ()
-- specializes to 0 on error
/--
info: def foo : IO Unit :=
have x := PUnit.unit.{0};
pure.{0, 0} Unit.unit
-/
#guard_msgs in set_option pp.universes true in #print foo
/-!
Test: Works for `have` too.
-/
/--
error: failed to infer universe levels in 'have' declaration type
PUnit.{_}
-/
#guard_msgs in
def foo' : IO Unit := do
have x : PUnit := PUnit.unit
pure ()
/-!
Test: Works for `fun` binders.
-/
/--
error: failed to infer universe levels in binder type
PUnit.{_}
-/
#guard_msgs in
example : Nat := (fun x : PUnit => 2) PUnit.unit
/-!
Test: A failure not in a binder, right now reports an error on `example`.
A change is that before the error was about level parameters rather than metavariables since
the def elaborator would turn all metavariables into parameters before this analysis.
-/
/--
error: declaration '_example' contains universe level metavariables at the expression
Function.const ({α : Sort _} → αα) 2 @id.{_}
in the declaration body
Function.const ({α : Sort _} → αα) 2 @id.{_}
-/
#guard_msgs in
example : Nat := Function.const _ 2 @id