LuaLS / LuaLS/lua-language-server
A union type should not merge class fields
Open
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?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
MacOS
What is the issue affecting?
Annotations
Expected Behaviour
---@class (exact) TypeA
---@field type 'A'
---@field commonField number
---@field specificFieldA number
---@class (exact) TypeB
---@field type 'B'
---@field commonField string
---@field specificFieldB string
---@alias Type_Either_A_Or_B_But_Not_Both TypeA|TypeB
---@type Type_Either_A_Or_B_But_Not_Both
local testA = {
type = 'A', --- Indicates that this should be of TypeA
commonField = 'test', --- Should be an error. TypeA.commonField should be a number
specificFieldA = 123, --- OK
specificFieldB = 'Hello' --- Should be an error. TypeA.specificFieldB doesn't exist
}
---@type Type_Either_A_Or_B_But_Not_Both
local testB = {
type = 'B', --- Indicates that this should be of TypeB
commonField = 'test', --- OK
specificFieldA = 123, --- Should be an error. TypeB.specificFieldA doesn't exist
specificFieldB = 'Hello' --- OK
}
Actual Behaviour
TypeA|TypeB is merged, so none of the mismatched fields/types are reported as errors.
local testA: TypeA|TypeB {
commonField: string|number,
specificFieldA: number,
specificFieldB: string,
type: 'A'|'B',
}
Reproduction steps
Paste the code into vscode
Additional Notes
No response
Log File
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the annotated TypeA|TypeB example in the Visual Studio Code extension, then trace how the language server merges union class fields. Done means the discriminator selects the correct class and reports the mismatched commonField and member-specific fields shown in the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100