summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/infer.lua4
-rw-r--r--script/core/searcher.lua21
-rw-r--r--test/type_inference/init.lua3
3 files changed, 20 insertions, 8 deletions
diff --git a/script/core/infer.lua b/script/core/infer.lua
index a4156263..770b48f9 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -191,6 +191,9 @@ end
local function cleanInfers(infers)
local version = config.config.runtime.version
local enableInteger = version == 'Lua 5.3' or version == 'Lua 5.4'
+ if infers['any'] and infers['nil'] then
+ infers['nil'] = nil
+ end
if infers['number'] then
enableInteger = false
end
@@ -227,6 +230,7 @@ local function cleanInfers(infers)
infers[BE_RETURN] = nil
infers['nil'] = nil
end
+ infers['any'] = nil
end
---合并对象的推断类型
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 9765777c..3ad11e3f 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -217,8 +217,8 @@ function m.searchRefsByID(status, uri, expect, mode)
local mark = {}
local function search(id, field)
- if ignoredIDs[id] then
- --return
+ if ignoredIDs[id] and field then
+ return
end
local cmark = mark[id]
if not cmark then
@@ -460,12 +460,17 @@ function m.searchRefsByID(status, uri, expect, mode)
searchNode(id, node, field)
end
local lastID = checkLastID(id, field)
- if lastID then
- local anyFieldID = lastID .. noder.ANY_FIELD
- local anyFieldNode = noder.getNodeByID(root, anyFieldID)
- if anyFieldNode then
- searchNode(anyFieldID, anyFieldNode, field)
- end
+ if not lastID then
+ return
+ end
+ local originField = id:sub(#lastID + 1)
+ if originField == noder.TABLE_KEY then
+ return
+ end
+ local anyFieldID = lastID .. noder.ANY_FIELD
+ local anyFieldNode = noder.getNodeByID(root, anyFieldID)
+ if anyFieldNode then
+ searchNode(anyFieldID, anyFieldNode, field)
end
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index d6f34ef0..2f01f67a 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -31,6 +31,9 @@ function TEST(wanted)
local source = getSource(pos)
assert(source)
local result = infer.searchAndViewInfers(source, 0)
+ if wanted ~= result then
+ infer.searchAndViewInfers(source, 0)
+ end
assert(wanted == result)
end
end