Zulip Chat Archive
Stream: lean4
Topic: Unexpected Editor Crash
Kaiyu Yang (Apr 17 2024 at 15:00):
Hi,
My Lean editor crashes when running the following code:
import Mathlib.Tactic
variable {α : Type u} {a b : Nat}
-- A sequence of α with index in [a, b]
-- Empty sequence if b < a
def Sequence (α : Type u) (a b : Nat) :=
{ arr : Array α // arr.size = max 0 (b - a + 1) }
def Sequence.get (s : Sequence α a b) (i : Nat) (h : a ≤ i ∧ i ≤ b) : α :=
s.1.get ⟨i - a, by
simp [s.2]
match h with
| ⟨h₁, h₂⟩ =>
have hab : a ≤ b := by linarith
have : i - a ≤ b - a := by simp [*]
linarith
⟩
instance : GetElem (Sequence α a b) ℕ α (fun _ i => a ≤ i ∧ i ≤ b) where
getElem := fun s i h => s.get i h
def s : Sequence ℕ 2 4 := ⟨#[1, 2, 3], rfl⟩
#eval s[5]
However, after removing variable {α : Type u} {a b : Nat}
, the code can run with the expected result below:
image.png
I'm wondering if variable {α : Type u} {a b : Nat}
makes any difference here. Thanks!
Kaiyu Yang (Apr 17 2024 at 15:03):
The issue can be reproduced on https://live.lean-lang.org/
Kim Morrison (Apr 18 2024 at 00:33):
It looks like this example might be easy to remove Mathlib from (which is pretty much a pre-requisite for getting bugs diagnosed / fixed). Does the same behaviour show after replacing the Mathlib tactics by sorry
(and replacing ℕ
with Nat
)?
Kaiyu Yang (Apr 18 2024 at 01:44):
Removing mathlib doesn't help. Below is a MWE:
def Sequence (α : Type u) (a b : Nat) :=
{ arr : Array α // arr.size = max 0 (b - a + 1) }
def Sequence.get (s : Sequence α a b) (i : Nat) (h : a ≤ i ∧ i ≤ b) : α :=
s.1.get ⟨i - a, by sorry⟩
instance : GetElem (Sequence α a b) Nat α (fun _ i => a ≤ i ∧ i ≤ b) where
getElem := fun s i h => s.get i h
def s : Sequence Nat 2 4 := ⟨#[1, 2, 3], rfl⟩
#eval s[5]
Now it crashes w/ or w/o variable {α : Type u} {a b : Nat}
.
Kim Morrison (Apr 18 2024 at 02:44):
That's great -- I wasn't expecting that removing mathlib would help, rather that now this makes a great issue to report on the lean4 repo. :-)
Mauricio Collares (Apr 18 2024 at 08:30):
Is this lean4#2252 (i.e., lean4#1697)?
Kim Morrison (Apr 18 2024 at 10:40):
Seems likely!
Last updated: May 02 2025 at 03:31 UTC