summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2021-10-01 14:32:01 +0800
committersumneko <sumneko@hotmail.com>2021-10-01 14:32:01 +0800
commit2183bf6e33a26216ecac691266462013a6359f68 (patch)
tree4487d3b044cf5d502d56c15d018b93b86b866ed8 /script
parent26595d420cb58772ddbe068de204e6df942c2405 (diff)
downloadlua-language-server-2183bf6e33a26216ecac691266462013a6359f68.zip
#693 no longer infer `nil`
Diffstat (limited to 'script')
-rw-r--r--script/core/infer.lua38
1 files changed, 7 insertions, 31 deletions
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 997df9a3..f1262d0e 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -4,7 +4,6 @@ local noder = require 'core.noder'
local util = require 'utility'
local vm = require "vm.vm"
-local BE_RETURN = {'BE_RETURN'}
local CLASS = {'CLASS'}
local TABLE = {'TABLE'}
@@ -17,7 +16,6 @@ local TypeSort = {
['function'] = 6,
['true'] = 101,
['false'] = 102,
- ['nil'] = 999,
}
local m = {}
@@ -166,10 +164,6 @@ local function searchInferOfValue(value, infers, mark)
infers['number'] = true
return true
end
- if value.type == 'nil' then
- infers['nil'] = true
- return true
- end
if value.type == 'function' then
infers['function'] = true
return true
@@ -241,9 +235,6 @@ local function cleanInfers(infers)
local version = config.get 'Lua.runtime.version'
local enableInteger = version == 'Lua 5.3' or version == 'Lua 5.4'
infers['unknown'] = nil
- if infers['any'] and infers['nil'] then
- infers['nil'] = nil
- end
if infers['number'] then
enableInteger = false
end
@@ -265,10 +256,6 @@ local function cleanInfers(infers)
infers[TABLE] = nil
infers['table'] = true
end
- if infers[BE_RETURN] then
- infers[BE_RETURN] = nil
- infers['nil'] = nil
- end
if infers['function'] then
for k in pairs(infers) do
if k:sub(1, 4) == 'fun(' then
@@ -276,13 +263,6 @@ local function cleanInfers(infers)
end
end
end
- infers['any'] = nil
- if infers['nil'] then
- infers['nil'] = nil
- if not next(infers) then
- infers['nil'] = true
- end
- end
end
---合并对象的推断类型
@@ -444,19 +424,15 @@ local function searchInfer(source, infers, mark)
end
-- check LuaDoc
local docName = m.getDocName(source)
- if docName then
+ if docName and docName ~= 'nil' and docName ~= 'unknown' then
infers[docName] = true
- if docName ~= 'unknown' then
- infers[CLASS] = true
+ if not vm.isBuiltinType(docName) then
+ infers[CLASS] = true
end
if docName == 'table' then
infers[TABLE] = true
end
end
- -- return XX
- if source.parent.type == 'return' then
- infers[BE_RETURN] = true
- end
end
local function searchLiteral(source, literals, mark)
@@ -635,14 +611,14 @@ function m.getClass(source)
local defs = vm.getDefs(source)
for _, def in ipairs(defs) do
if def.type == 'doc.class.name' then
- infers[def[1]] = true
+ if not vm.isBuiltinType(def[1]) then
+ infers[def[1]] = true
+ end
end
end
cleanInfers(infers)
- infers['nil'] = nil
local view = m.viewInfers(infers)
- if view == 'any'
- or view == 'nil' then
+ if view == 'any' then
return nil
end
return view