lean4-htt/tests/elab/1697.lean
Kyle Miller e804829101
feat: have #eval elaborate variables (#11427)
This PR modifies `#eval e` to elaborate `e` with section variables in
scope. While evaluating expressions with free variables is not possible,
this lets `#eval` give a better error message than "unknown identifier."

Example:
```lean
section
variable (n : Nat)
/-- error: Cannot evaluate, contains free variable `n` -/
#guard_msgs in #eval n
end
```

The error is localized to `#eval`. It would be more friendly if the
error were to be placed on uses of free variables.

[Zulip
discussion](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Unknown.20identifier.20error.20messages.20for.20.60.23eval.60/near/560864544)
2026-03-09 04:52:08 +00:00

43 lines
885 B
Text

/--
error: Tactic `decide` proved that the proposition
False
is false
-/
#guard_msgs in
#eval show Nat from False.elim (by decide)
/--
error: Aborting evaluation since the expression depends on the 'sorry' axiom, which can lead to runtime instability and crashes.
To attempt to evaluate anyway despite the risks, use the '#eval!' command.
---
warning: declaration uses `sorry`
-/
#guard_msgs in
#eval #[1,2,3][2]'sorry
/--
info: 3
---
warning: declaration uses `sorry`
-/
#guard_msgs in
#eval! #[1,2,3][2]'sorry
/-
With this test I wanted to show that `#eval!` can be used to do unsafe operations. Under
normal circumstances this actually works with the output below, but the `Linux Debug` CI build
catches it and complains. Maybe too bold to have this in the test suite.
/--
warning: declaration uses `sorry`
---
info: 3
-/
#guard_msgs in
#eval! (#[1,2,3].pop)[2]'sorry
-/