Skip to content

Commit 02f6831

Browse files
committed
fix wrong infer of tableindex
#1831
1 parent f5d631b commit 02f6831

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Diff for: script/vm/infer.lua

+4-9
Original file line numberDiff line numberDiff line change
@@ -555,19 +555,14 @@ function vm.viewKey(source, uri)
555555
return '[' .. key .. ']'
556556
end
557557
end
558-
if source.type == 'tableindex' then
558+
if source.type == 'tableindex'
559+
or source.type == 'setindex' then
559560
local index = source.index
560-
local name = vm.getKeyName(index)
561+
local name = vm.getInfer(index):viewLiterals()
561562
if not name then
562563
return nil
563564
end
564-
local key
565-
if index.type == 'string' then
566-
key = util.viewString(name, index[2])
567-
else
568-
key = util.viewLiteral(name)
569-
end
570-
return ('[%s]'):format(key), name
565+
return ('[%s]'):format(name), name
571566
end
572567
if source.type == 'tableexp' then
573568
return ('[%d]'):format(source.tindex), source.tindex

Diff for: test/hover/init.lua

+17
Original file line numberDiff line numberDiff line change
@@ -2430,3 +2430,20 @@ local t: {
24302430
['y']: integer = 2,
24312431
}
24322432
]]
2433+
2434+
TEST [[
2435+
local enum = { a = 1, b = 2 }
2436+
2437+
local <?t?> = {
2438+
[enum.a] = true,
2439+
[enum.b] = 2,
2440+
[3] = {}
2441+
}
2442+
]]
2443+
[[
2444+
local t: {
2445+
[1]: boolean = true,
2446+
[2]: integer = 2,
2447+
[3]: table,
2448+
}
2449+
]]

0 commit comments

Comments
 (0)