Closed
Description
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, Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
Building on #2214 (comment), the following code should work without any warnings:
---@class Foo
---@field a number
---@field b number
---@class Bar
---@field aa number
---@field bb number
---@type Foo|Bar
local fb = {
aa = 1,
bb = 2
}
---@param foobar Foo|Bar
local function func(foobar) end
func {
aa = 1,
bb = 2
}
Actual Behaviour
I get missing field warning when defining the local variable fb
, and when calling the function func
: "Missing fields: a
, b
"
It seems to depend on the order of classes in the union. For example, this works (placing Bar before Foo):
---@type Bar|Foo
local fb = {
aa = 1,
bb = 2
}
But the following doesn't:
---@type Bar|Foo
local fb = {
a = 1,
b = 2
}
Reproduction steps
Paste the sample code in your editor.
Additional Notes
No response
Log File
No response