blob: 867d013594563f8eeab354cfd10e60eb05026514 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
local files = require 'files'
local guide = require 'parser.guide'
local vm = require 'vm'
local lang = require 'language'
return function (uri, callback)
local state = files.getState(uri)
if not state then
return
end
guide.eachSourceType(state.ast, 'getlocal', function (src)
local checkNil
local nxt = src.next
if nxt then
if nxt.type == 'getfield'
or nxt.type == 'getmethod'
or nxt.type == 'getindex'
or nxt.type == 'call' then
checkNil = true
end
end
local call = src.parent
if call and call.type == 'call' and call.node == src then
checkNil = true
end
local setIndex = src.parent
if setIndex and setIndex.type == 'setindex' and setIndex.index == src then
checkNil = true
end
if not checkNil then
return
end
local node = vm.compileNode(src)
if node:hasFalsy() and not vm.getInfer(src):hasType(uri, 'any') then
callback {
start = src.start,
finish = src.finish,
message = lang.script('DIAG_NEED_CHECK_NIL'),
}
end
end)
end
|