summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-06 22:58:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-06 22:58:11 +0800
commit9be846d86c494e08d376aa465e8269796176765a (patch)
tree04027cdb5ae6a118739a92911dbbd6797a39939f /script/vm/compiler.lua
parentdcca81c4fa7bd9b745123be8be0c8b07fcd6e29a (diff)
downloadlua-language-server-9be846d86c494e08d376aa465e8269796176765a.zip
type check: check the fields in table
resolve #1434
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua68
1 files changed, 38 insertions, 30 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 9e8acb0a..7ef6086c 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -320,43 +320,51 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
hasFounded[fieldKey] = true
end
end
- elseif key and not hasFounded[key] then
- local keyType = type(key)
- if keyType == 'table' then
- -- ---@field [integer] boolean -> class[integer]
+ goto CONTINUE
+ end
+ if key == nil then
+ pushResult(field, true)
+ goto CONTINUE
+ end
+ if hasFounded[key] then
+ goto CONTINUE
+ end
+ local keyType = type(key)
+ if keyType == 'table' then
+ -- ---@field [integer] boolean -> class[integer]
+ local fieldNode = vm.compileNode(field.field)
+ if vm.isSubType(suri, key.name, fieldNode) then
+ local nkey = '|' .. key.name
+ if not searchedFields[nkey] then
+ pushResult(field, true)
+ hasFounded[nkey] = true
+ end
+ end
+ else
+ local typeName
+ if keyType == 'number' then
+ if math.tointeger(key) then
+ typeName = 'integer'
+ else
+ typeName = 'number'
+ end
+ elseif keyType == 'boolean'
+ or keyType == 'string' then
+ typeName = keyType
+ end
+ if typeName and field.field.type ~= 'doc.field.name' then
+ -- ---@field [integer] boolean -> class[1]
local fieldNode = vm.compileNode(field.field)
- if vm.isSubType(suri, key.name, fieldNode) then
- local nkey = '|' .. key.name
+ if vm.isSubType(suri, typeName, fieldNode) then
+ local nkey = '|' .. typeName
if not searchedFields[nkey] then
pushResult(field, true)
hasFounded[nkey] = true
end
end
- else
- local typeName
- if keyType == 'number' then
- if math.tointeger(key) then
- typeName = 'integer'
- else
- typeName = 'number'
- end
- elseif keyType == 'boolean'
- or keyType == 'string' then
- typeName = keyType
- end
- if typeName and field.field.type ~= 'doc.field.name' then
- -- ---@field [integer] boolean -> class[1]
- local fieldNode = vm.compileNode(field.field)
- if vm.isSubType(suri, typeName, fieldNode) then
- local nkey = '|' .. typeName
- if not searchedFields[nkey] then
- pushResult(field, true)
- hasFounded[nkey] = true
- end
- end
- end
end
end
+ ::CONTINUE::
end
copyToSearched()
-- check local field and global field
@@ -1667,7 +1675,7 @@ local compilerSwitch = util.switch()
end)
: case 'doc.field.name'
: call(function (source)
- vm.setNode(source, vm.compileNode(source.parent))
+ vm.setNode(source, source)
end)
: case 'doc.type.field'
: call(function (source)