diff options
Diffstat (limited to 'script/core/diagnostics/unreachable-code.lua')
-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 |