Interpreter crash with `unreachable`
Open
@zwarich is already working on this.
Since Mar 9, 2025.
bug
code-generator
P-medium
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Checked that your issue isn't already filed.
- Reduced the issue to a self-contained, reproducible test case.
Description
Lean4 language server crashes with unreachable while I was editing a function in VSCode. Obviously, the code is syntactically malformed, but the observed behaviour seems unexpected.
This is reproducable on both stable and nightly, windows and linux.
I was able to reduce the file to the following:
import Lean
import Lean.Meta
def some_work_in_progress_code (input : Lean.Expr) (vars : Std.HashMap Lean.Expr Nat) :
Lean.Expr -> (Std.HashMap Lean.Expr Nat) × Lean.Expr
| L -- This line is work in progress. I was typing
| Lean.Expr.app (Lean.Expr.app _ lhs) rhs =>
let (vars, lhs) :=some_work_in_progress_code input vars lhs
(vars, .const `stuff [])
| e => (vars, .const `stuff [])
elab "stuff" : tactic => do
Lean.Elab.Tactic.withMainContext <| do
let goal <- Lean.Elab.Tactic.getMainTarget
if let some (input, lhs, rhs) := <- Lean.Meta.matchEq? goal then
let vars :=Std.mkHashMap
let (vars, lhs) :=some_work_in_progress_code input vars lhs
Lean.logInfo <| lhs
example : ∀ x y : Nat, x = x + y :=by
intro x y
stuff
sorry
Steps to Reproduce
- Copy the above snippet to VSCode with a Lean4 plugin installed
- Alternatively, just save the above snippet to a .lean file and call the lean executable on it
Expected behavior:
No crash. Just a red squiggle
Actual behavior:
The lean4 executable crashes with unreachable
Reproduces how often:
Always
Versions
- Stable on Windows 11: Lean (version 4.0.0, commit 7dbfaf9b7519, Release)
- Nightly on Gitpod (Ubuntu 20.04.4 LTS) : Lean (version 4.0.0-nightly-2022-08-28, commit cd0dd4cc2fb4, Release)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.