summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-08 17:40:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-08 17:40:52 +0800
commitf82740088014a0dcd29dcefd29ef7e019b71a772 (patch)
treebe1b4ceb7b86a353a05b0d307d9ceb1cd8de68cb /script/vm
parentdecf02ad1f708f9e2eb7d50d9765b22ae21f0425 (diff)
downloadlua-language-server-f82740088014a0dcd29dcefd29ef7e019b71a772.zip
check type for `Enum -> Other`
fix #1675
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/global.lua2
-rw-r--r--script/vm/type.lua45
2 files changed, 40 insertions, 7 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 6f3bcb68..1bd7576d 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -378,13 +378,11 @@ local compilerGlobalSwitch = util.switch()
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
diff --git a/script/vm/type.lua b/script/vm/type.lua
index 05b76fc3..57a6444f 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -50,9 +50,10 @@ end
---@param parentName string
---@param child vm.node.object
---@param uri uri
+---@param mark table
---@param errs? typecheck.err[]
---@return boolean?
-local function checkEnum(parentName, child, uri, errs)
+local function checkParentEnum(parentName, child, uri, mark, errs)
local parentClass = vm.getGlobal('type', parentName)
if not parentClass then
return nil
@@ -70,7 +71,7 @@ local function checkEnum(parentName, child, uri, errs)
if child.type == 'global' then
---@cast child vm.global
for _, enum in ipairs(enums) do
- if vm.isSubType(uri, child, vm.compileNode(enum)) then
+ if vm.isSubType(uri, child, vm.compileNode(enum), mark) then
return true
end
end
@@ -131,6 +132,35 @@ local function checkEnum(parentName, child, uri, errs)
end
end
+---@param childName string
+---@param parent vm.node.object
+---@param uri uri
+---@param mark table
+---@param errs? typecheck.err[]
+---@return boolean?
+local function checkChildEnum(childName, parent , uri, mark, errs)
+ local childClass = vm.getGlobal('type', childName)
+ if not childClass then
+ return nil
+ end
+ local enums
+ for _, set in ipairs(childClass:getSets(uri)) do
+ if set.type == 'doc.enum' then
+ enums = vm.getEnums(set)
+ break
+ end
+ end
+ if not enums then
+ return nil
+ end
+ for _, enum in ipairs(enums) do
+ if not vm.isSubType(uri, vm.compileNode(enum), parent, mark ,errs) then
+ return false
+ end
+ end
+ return true
+end
+
---@param parent vm.node.object
---@param child vm.node.object
---@param mark table
@@ -389,9 +419,14 @@ function vm.isSubType(uri, child, parent, mark, errs)
return true
end
- local isEnum = checkEnum(parentName, child, uri, errs)
- if isEnum ~= nil then
- return isEnum
+ local result = checkParentEnum(parentName, child, uri, mark, errs)
+ if result ~= nil then
+ return result
+ end
+
+ result = checkChildEnum(childName, parent, uri, mark, errs)
+ if result ~= nil then
+ return result
end
if parentName == 'table' and not guide.isBasicType(childName) then