diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-29 16:22:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-29 16:22:02 +0800 |
commit | f78d4944b4d811956b6b1493b8a022f633babfdd (patch) | |
tree | 4aef213c2d95fee825d6dede008099174df27c9f /script | |
parent | 2b9fe7484f0d3f1bf4a287ac5d563896b713efa7 (diff) | |
download | lua-language-server-f78d4944b4d811956b6b1493b8a022f633babfdd.zip |
fix #1406
Diffstat (limited to 'script')
-rw-r--r-- | script/core/diagnostics/unreachable-code.lua | 18 |
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 |