diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/diagnostics/unreachable-code.lua | 18 | ||||
-rw-r--r-- | test/diagnostics/common.lua | 14 |
3 files changed, 32 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 7eeba2b9..ed98c1e4 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## 3.5.2 * `FIX` [#1395](https://github.com/sumneko/lua-language-server/issues/1395) * `FIX` [#1403](https://github.com/sumneko/lua-language-server/issues/1403) +* `FIX` [#1406](https://github.com/sumneko/lua-language-server/issues/1406) ## 3.5.1 `2022-7-26` 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 diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 9d337e53..e10ac52c 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -2053,3 +2053,17 @@ function m.ff(x) end m.ff(1) ]] + +TEST [[ +local done = false + +local function set_done() + done = true +end + +while not done do + set_done() +end + +print(1) +]] |