Skip to content

Notation x[...]'... gets confused with a character literal #609

@Rob23oba

Description

@Rob23oba

Description

Indexing notation with proof is sometimes mistaken with a character literal, which can cause formatting to look weird later:

Image

Context

I discovered this while working on hash map code:
leanprover/lean4#7400 (comment)

Steps to Reproduce

@[simp]
def foo (x : Array Nat) (i : Nat) (h' : i < x.size) :
    0 ≤ x[i]'h' :=
  Nat.zero_le _

@[simp]
def bar (x : Array Nat) (i' : Nat) (h : i' < x.size) :
    0 ≤ x[i']'h :=
  Nat.zero_le _

@[simp]
def baz : 2 = 2 := rfl

Expected behavior:
The [...] should be detected as a closed pair of brackets, the ' afterwards shouldn't get any special formatting.

Actual behavior:
In the first case, the [..] is detected as closed pair of brackets; however, the ' afterwards gets highlighted like a character literal, the remainder of the "character literal" is overriden by the semantic highlighting information from the server.
In the second case it treats [ as unclosed and ']' as a character literal (although the first quote gets again overriden by semantic highlighting). Due to fact that it treats [ as unclosed, the remainder has slightly wrong highlighting, e.g. @[simp] in baz isn't recognized as an attribute.

Versions

Version 0.0.202

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions