summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-29 16:22:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-29 16:22:02 +0800
commitf78d4944b4d811956b6b1493b8a022f633babfdd (patch)
tree4aef213c2d95fee825d6dede008099174df27c9f /script
parent2b9fe7484f0d3f1bf4a287ac5d563896b713efa7 (diff)
downloadlua-language-server-f78d4944b4d811956b6b1493b8a022f633babfdd.zip
fix #1406
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/unreachable-code.lua18
1 files changed, 17 insertions, 1 deletions
diff --git a/script/core/diagnostics/unreachable-code.lua b/script/core/diagnostics/unreachable-code.lua
index 772a1764..4f0a38b7 100644
--- a/script/core/diagnostics/unreachable-code.lua
+++ b/script/core/diagnostics/unreachable-code.lua
@@ -5,6 +5,21 @@ local lang = require 'language'
local await = require 'await'
local define = require 'proto.define'
+---@param source parser.object
+---@return boolean
+local function allLiteral(source)
+ local result = true
+ guide.eachSource(source, function (src)
+ if src.type ~= 'unary'
+ and src.type ~= 'binary'
+ and not guide.isLiteral(src) then
+ result = false
+ return false
+ end
+ end)
+ return result
+end
+
---@param block parser.object
---@return boolean
local function hasReturn(block)
@@ -25,7 +40,8 @@ local function hasReturn(block)
else
if block.type == 'while' then
if vm.testCondition(block.filter)
- and not block.breaks then
+ and not block.breaks
+ and allLiteral(block.filter) then
return true
end
end