Skip to content

Commit 3cadbfc

Browse files
committed
fix infer of unknown and unknown
1 parent 0652fa5 commit 3cadbfc

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

make/bootstrap.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ package.searchers[2] = function (name)
6969
return err
7070
end
7171
local f = io.open(filename)
72+
if not f then
73+
return 'cannot open file:' .. filename
74+
end
7275
local buf = f:read '*a'
7376
f:close()
7477
local relative = filename:sub(1, #root) == root and filename:sub(#root + 2) or filename

script/core/diagnostics/need-check-nil.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ return function (uri, callback)
3232
callback {
3333
start = src.start,
3434
finish = src.finish,
35-
message = lang.script('DIAG_MISS_NEED_CHECK_NIL'),
35+
message = lang.script('DIAG_NEED_CHECK_NIL'),
3636
}
3737
end
3838
end)

script/vm/compiler.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,7 @@ local compilerSwitch = util.switch()
14351435
elseif r1 == false then
14361436
vm.setNode(source, node1)
14371437
else
1438-
vm.getNode(source):merge(node2)
1439-
vm.getNode(source):addOptional()
1438+
vm.setNode(source, node2)
14401439
end
14411440
end
14421441
if source.op.type == 'or' then

script/vm/infer.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ function mt:view(default, uri)
294294
end
295295
end
296296

297-
if #array == 0 then
298-
return default or 'unknown'
299-
end
300-
301297
table.sort(array, function (a, b)
302298
local sa = inferSorted[a] or 0
303299
local sb = inferSorted[b] or 0
@@ -311,13 +307,17 @@ function mt:view(default, uri)
311307
local limit = config.get(uri or self.uri, 'Lua.hover.enumsLimit')
312308

313309
local view
314-
if max > limit then
315-
view = string.format('%s...(+%d)'
316-
, table.concat(array, '|', 1, limit)
317-
, max - limit
318-
)
310+
if #array == 0 then
311+
view = default or 'unknown'
319312
else
320-
view = table.concat(array, '|')
313+
if max > limit then
314+
view = string.format('%s...(+%d)'
315+
, table.concat(array, '|', 1, limit)
316+
, max - limit
317+
)
318+
else
319+
view = table.concat(array, '|')
320+
end
321321
end
322322

323323
if self.node:isOptional() then

test/diagnostics/common.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,3 +1494,10 @@ local x
14941494
14951495
S = <!x!>()
14961496
]]
1497+
1498+
TEST [[
1499+
local x, y
1500+
local z = x and y
1501+
1502+
print(z.y)
1503+
]]

test/type_inference/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,3 +1915,7 @@ local t
19151915
19161916
local <?x?> = t[1]
19171917
]]
1918+
1919+
TEST 'unknown' [[
1920+
local <?x?> = y and z
1921+
]]

0 commit comments

Comments
 (0)