Skip to content

Commit fa97748

Browse files
committed
Limit boolean-context checks to conditions
1 parent ed06935 commit fa97748

File tree

2 files changed

+3
-42
lines changed

2 files changed

+3
-42
lines changed

script/core/diagnostics/boolean-context.lua

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,6 @@ end
3535

3636
---@param source parser.object?
3737
---@return boolean
38-
local function isConditionFilter(source)
39-
if not source or not source.parent then
40-
return false
41-
end
42-
local parent = source.parent
43-
if parent.type ~= 'ifblock'
44-
and parent.type ~= 'elseifblock'
45-
and parent.type ~= 'while'
46-
and parent.type ~= 'repeat' then
47-
return false
48-
end
49-
return parent.filter == source
50-
end
51-
5238
---@param source parser.object?
5339
---@param uri uri
5440
---@param callback fun(result: diag.result)
@@ -92,23 +78,10 @@ return function (uri, callback)
9278
and source.filter.type == 'binary'
9379
and source.filter.op
9480
and (source.filter.op.type == 'and' or source.filter.op.type == 'or') then
81+
checkExpression(source.filter[1], uri, callback)
82+
checkExpression(source.filter[2], uri, callback)
9583
return
9684
end
9785
checkExpression(source.filter, uri, callback)
9886
end)
99-
100-
---@async
101-
guide.eachSourceType(state.ast, 'binary', function (source)
102-
await.delay()
103-
local op = source.op and source.op.type
104-
if op ~= 'and' and op ~= 'or' then
105-
return
106-
end
107-
if isConditionFilter(source) then
108-
checkExpression(source[1], uri, callback)
109-
checkExpression(source[2], uri, callback)
110-
return
111-
end
112-
checkExpression(source[1], uri, callback)
113-
end)
11487
end

test/diagnostics/boolean-context.lua

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ if <!a!> then end
55
66
---@type number
77
local b
8-
if not b then end
9-
10-
---@type number
11-
local c
12-
local x = <!c!> or "3"
13-
14-
---@type false
15-
local d
16-
local y = d and "4"
8+
if <!b!> then end
179
1810
---@type boolean
1911
local e
@@ -34,8 +26,4 @@ if <!h!> and true then end
3426
---@type number
3527
local i
3628
if true and <!i!> then end
37-
38-
---@type any
39-
local f
40-
local z = f or "3"
4129
]]

0 commit comments

Comments
 (0)