Skip to content

Commit f78d494

Browse files
committed
fix #1406
1 parent 2b9fe74 commit f78d494

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.5.2
44
* `FIX` [#1395](https://github.com/sumneko/lua-language-server/issues/1395)
55
* `FIX` [#1403](https://github.com/sumneko/lua-language-server/issues/1403)
6+
* `FIX` [#1406](https://github.com/sumneko/lua-language-server/issues/1406)
67

78
## 3.5.1
89
`2022-7-26`

script/core/diagnostics/unreachable-code.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ local lang = require 'language'
55
local await = require 'await'
66
local define = require 'proto.define'
77

8+
---@param source parser.object
9+
---@return boolean
10+
local function allLiteral(source)
11+
local result = true
12+
guide.eachSource(source, function (src)
13+
if src.type ~= 'unary'
14+
and src.type ~= 'binary'
15+
and not guide.isLiteral(src) then
16+
result = false
17+
return false
18+
end
19+
end)
20+
return result
21+
end
22+
823
---@param block parser.object
924
---@return boolean
1025
local function hasReturn(block)
@@ -25,7 +40,8 @@ local function hasReturn(block)
2540
else
2641
if block.type == 'while' then
2742
if vm.testCondition(block.filter)
28-
and not block.breaks then
43+
and not block.breaks
44+
and allLiteral(block.filter) then
2945
return true
3046
end
3147
end

test/diagnostics/common.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,3 +2053,17 @@ function m.ff(x) end
20532053
20542054
m.ff(1)
20552055
]]
2056+
2057+
TEST [[
2058+
local done = false
2059+
2060+
local function set_done()
2061+
done = true
2062+
end
2063+
2064+
while not done do
2065+
set_done()
2066+
end
2067+
2068+
print(1)
2069+
]]

0 commit comments

Comments
 (0)