previously, `#eval` would happily evaluate expressions that contain `sorry`, either explicitly or because of failing tactics. In conjunction with operations like array access this can lead to the lean process crashing, which isn't particularly great. So how `#eval` will refuse to run code that (transitively) depends on the `sorry` axiom (using the same code as `#print axioms`). If the user really wants to run it, they can use `#eval!`. Closes #1697
37 lines
894 B
Text
37 lines
894 B
Text
import Lean
|
|
open Lean Elab Meta
|
|
|
|
def somethingBad : MetaM Nat := do
|
|
IO.println "oh no"
|
|
return 1
|
|
|
|
/--
|
|
error: invalid use of `(<- ...)`, must be nested inside a 'do' expression
|
|
---
|
|
error: cannot evaluate expression that depends on the `sorry` axiom.
|
|
Use `#eval!` to evaluate nevertheless (which may cause lean to crash).
|
|
-/
|
|
#guard_msgs in
|
|
#eval show MetaM Unit from do
|
|
let t := if false then ← somethingBad else 9
|
|
|
|
def foo : MetaM Bool :=
|
|
return false
|
|
|
|
/--
|
|
error: invalid use of `(<- ...)`, must be nested inside a 'do' expression
|
|
---
|
|
error: cannot evaluate expression that depends on the `sorry` axiom.
|
|
Use `#eval!` to evaluate nevertheless (which may cause lean to crash).
|
|
-/
|
|
#guard_msgs in
|
|
#eval show MetaM Unit from do
|
|
let t := if (← foo) then ← somethingBad else 9
|
|
|
|
/--
|
|
info: 1
|
|
-/
|
|
#guard_msgs in
|
|
#eval show MetaM Nat from do
|
|
let t := if (← foo) then 0 else 1
|
|
return t
|