summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-08 03:06:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-08 03:06:42 +0800
commitbe3dfa4a1b5cce947578a37935c38c4c3d2bae19 (patch)
tree80c079816726e7d52b18f85b8bda349d835e1c39
parent8c5941c4573f0c88525846fb01fd5100a3aef607 (diff)
downloadlua-language-server-be3dfa4a1b5cce947578a37935c38c4c3d2bae19.zip
auto create class for enum fields
#1410
-rw-r--r--script/vm/global.lua13
-rw-r--r--test/type_inference/init.lua15
2 files changed, 26 insertions, 2 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 6db3a58c..6f3bcb68 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -374,9 +374,18 @@ local compilerGlobalSwitch = util.switch()
end
source._enums = {}
for _, field in ipairs(tbl) do
- if field.type == 'tablefield'
- or field.type == 'tableindex' then
+ if field.type == 'tablefield' then
source._enums[#source._enums+1] = field
+ local subType = vm.declareGlobal('type', name .. '.' .. field.field[1], uri)
+ subType:addSet(uri, field)
+ field._globalNode = subType
+ elseif field.type == 'tableindex' then
+ source._enums[#source._enums+1] = field
+ if field.index.type == 'string' then
+ local subType = vm.declareGlobal('type', name .. '.' .. field.index[1], uri)
+ subType:addSet(uri, field)
+ field._globalNode = subType
+ end
end
end
end)
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 6032cd0f..83f948cb 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -3947,3 +3947,18 @@ end
local <?x?> = f(true)
]]
+
+TEST 'boolean' [[
+---@enum A
+local e = {
+ x = 1,
+ y = 2,
+}
+
+---@param p A
+---@overload fun(P: A.x): boolean
+---@overload fun(p: A.y): number
+local function f(p) end
+
+local <?r?> = f(e.x)
+]]