LuaLS / LuaLS/lua-language-server

Using a union of string literals as a table key doesn't force use of the keys

Open
#2,495 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour
---@alias SomeUnion
--- | 'a'
--- | 'b'

---@type table<SomeUnion, number>
local a

should work roughly like

---@class (exact) SomeUnion
---@field a number
---@field b number
local a
Actual Behaviour

image

Reproduction steps
---@alias SomeUnion
--- | 'a'
--- | 'b'

---@type table<SomeUnion, number>
local a = {
  c = "should be invalid"
}
Additional Notes

No response

Log File

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported type-checking example in the issue and trace the language server's handling of table keys whose type is a string-literal union. Done means the c key in the reproduction is reported invalid while the a and b keys remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.