Skip to content

Commit f40f0a5

Browse files
committed
need-check-nil check t[x]
1 parent fde5288 commit f40f0a5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ return function (uri, callback)
2424
if call and call.type == 'call' and call.node == src then
2525
checkNil = true
2626
end
27+
local setIndex = src.parent
28+
if setIndex and setIndex.type == 'setindex' and setIndex.index == src then
29+
checkNil = true
30+
end
2731
if not checkNil then
2832
return
2933
end

test/diagnostics/common.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,14 @@ local x
15601560
S = <!x!>()
15611561
]]
15621562

1563+
TEST [[
1564+
---@type integer?
1565+
local x
1566+
1567+
T = {}
1568+
T[<!x!>] = 1
1569+
]]
1570+
15631571
TEST [[
15641572
local x, y
15651573
local z = x and y

0 commit comments

Comments
 (0)