Skip to content

LSP crash when indexing out of bounds #2252

@sullyj3

Description

@sullyj3

Prerequisites

  • [X ] 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

LSP server crash when indexing arrays out of bounds. Note that I'm using regular indexing arr[idx], not the unchecked arr[idx]! version. I believe crashing for unchecked out of bounds indexing is expected behaviour.

The behaviour seems to differ between combinations of array length and index.

Steps to Reproduce

Paste into vscode with lean 4 extension running

def northernTrees : Array String :=
  #["sloe", "birch", "elm", "oak"]

#eval northernTrees[4]

Expected behavior: [What you expect to happen]
no crash

Actual behavior: [What actually happens]
lsp crashes. It also crashes with northernTrees[5], but curiously northernTrees[6] gives a type error without crashing, as expected.

Reproduces how often: [What percentage of the time does it reproduce?]
100% for this particular case.

At first I thought the rule was arr[arr.length] and arr[arr.length+1] cause crashes and other indices don't. However this doesn't generalize to arrays of different lengths, eg with array of one element

def northernTrees : Array String :=
  #["sloe"]

All indices from 1 to 10 inclusive cause the crash consistently (I didn't keep testing with higher indices)

Versions

Lean (version 4.0.0-nightly-2023-05-22, commit 8d4dd23, Release)

Arch linux (rolling release)

Additional Information

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions