Skip to content

multi-line type aliases parse table indexers weirdly #2056

@goldenstein64

Description

@goldenstein64

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Annotations

Expected Behaviour

This type alias should parse as { [1]: string } | number.

---@alias Some
---| { [1]: string }
---| number

local x ---@type Some

print(x)

Actual Behaviour

The type alias can't be parsed and is left as a free Some type.

image

Reproduction steps

  1. Open a file
  2. Write the following text
---@alias Some
---| { [1]: string }
---| number

local x ---@type Some

print(x)
  1. Find that Some can't be parsed and is left as a free type, shown when x is hovered over

Additional Notes

Following the LSP's expected X hovers, it completes itself to an alias like { [1|number]: "type name" }.

---@alias Some
---| { [1]: string }
---| number]: "type name" }

local x ---@type Some

print(x)

It looks like everything after { [1 is ignored and the rest of the line is treated as a comment.

This can be circumvented by putting all the types on one line.

---@alias Some { [1]: string } | number

Log File

lua-language-server.log

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