summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-23 23:46:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-23 23:46:53 +0800
commit3cadbfc7419542a8b56f0996bfbfbda146a30ea5 (patch)
tree216f4c4afff1240c84b395901bf7a7b0a9f78239
parent0652fa586d62408e28d8f7d253aa96381d357bc8 (diff)
downloadlua-language-server-3cadbfc7419542a8b56f0996bfbfbda146a30ea5.zip
fix infer of `unknown and unknown`
-rw-r--r--make/bootstrap.lua3
-rw-r--r--script/core/diagnostics/need-check-nil.lua2
-rw-r--r--script/vm/compiler.lua3
-rw-r--r--script/vm/infer.lua20
-rw-r--r--test/diagnostics/common.lua7
-rw-r--r--test/type_inference/init.lua4
6 files changed, 26 insertions, 13 deletions
diff --git a/make/bootstrap.lua b/make/bootstrap.lua
index 6c27cf95..00036f34 100644
--- a/make/bootstrap.lua
+++ b/make/bootstrap.lua
@@ -69,6 +69,9 @@ package.searchers[2] = function (name)
return err
end
local f = io.open(filename)
+ if not f then
+ return 'cannot open file:' .. filename
+ end
local buf = f:read '*a'
f:close()
local relative = filename:sub(1, #root) == root and filename:sub(#root + 2) or filename
diff --git a/script/core/diagnostics/need-check-nil.lua b/script/core/diagnostics/need-check-nil.lua
index 8654a7a6..98fdfd08 100644
--- a/script/core/diagnostics/need-check-nil.lua
+++ b/script/core/diagnostics/need-check-nil.lua
@@ -32,7 +32,7 @@ return function (uri, callback)
callback {
start = src.start,
finish = src.finish,
- message = lang.script('DIAG_MISS_NEED_CHECK_NIL'),
+ message = lang.script('DIAG_NEED_CHECK_NIL'),
}
end
end)
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 1f33a784..c69a7724 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1435,8 +1435,7 @@ local compilerSwitch = util.switch()
elseif r1 == false then
vm.setNode(source, node1)
else
- vm.getNode(source):merge(node2)
- vm.getNode(source):addOptional()
+ vm.setNode(source, node2)
end
end
if source.op.type == 'or' then
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index b5e717d5..410f9795 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -294,10 +294,6 @@ function mt:view(default, uri)
end
end
- if #array == 0 then
- return default or 'unknown'
- end
-
table.sort(array, function (a, b)
local sa = inferSorted[a] or 0
local sb = inferSorted[b] or 0
@@ -311,13 +307,17 @@ function mt:view(default, uri)
local limit = config.get(uri or self.uri, 'Lua.hover.enumsLimit')
local view
- if max > limit then
- view = string.format('%s...(+%d)'
- , table.concat(array, '|', 1, limit)
- , max - limit
- )
+ if #array == 0 then
+ view = default or 'unknown'
else
- view = table.concat(array, '|')
+ if max > limit then
+ view = string.format('%s...(+%d)'
+ , table.concat(array, '|', 1, limit)
+ , max - limit
+ )
+ else
+ view = table.concat(array, '|')
+ end
end
if self.node:isOptional() then
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 72b2db6c..5f1d01c8 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1494,3 +1494,10 @@ local x
S = <!x!>()
]]
+
+TEST [[
+local x, y
+local z = x and y
+
+print(z.y)
+]]
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 64cc43a8..a9ea81a7 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1915,3 +1915,7 @@ local t
local <?x?> = t[1]
]]
+
+TEST 'unknown' [[
+local <?x?> = y and z
+]]