Skip to content

Commit be3dfa4

Browse files
committed
auto create class for enum fields
#1410
1 parent 8c5941c commit be3dfa4

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

script/vm/global.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,18 @@ local compilerGlobalSwitch = util.switch()
374374
end
375375
source._enums = {}
376376
for _, field in ipairs(tbl) do
377-
if field.type == 'tablefield'
378-
or field.type == 'tableindex' then
377+
if field.type == 'tablefield' then
379378
source._enums[#source._enums+1] = field
379+
local subType = vm.declareGlobal('type', name .. '.' .. field.field[1], uri)
380+
subType:addSet(uri, field)
381+
field._globalNode = subType
382+
elseif field.type == 'tableindex' then
383+
source._enums[#source._enums+1] = field
384+
if field.index.type == 'string' then
385+
local subType = vm.declareGlobal('type', name .. '.' .. field.index[1], uri)
386+
subType:addSet(uri, field)
387+
field._globalNode = subType
388+
end
380389
end
381390
end
382391
end)

test/type_inference/init.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,3 +3947,18 @@ end
39473947
39483948
local <?x?> = f(true)
39493949
]]
3950+
3951+
TEST 'boolean' [[
3952+
---@enum A
3953+
local e = {
3954+
x = 1,
3955+
y = 2,
3956+
}
3957+
3958+
---@param p A
3959+
---@overload fun(P: A.x): boolean
3960+
---@overload fun(p: A.y): number
3961+
local function f(p) end
3962+
3963+
local <?r?> = f(e.x)
3964+
]]

0 commit comments

Comments
 (0)