summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-14 16:29:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-14 16:29:15 +0800
commit0d79784ccf47a03f9f35e1afbd579ecbab0acd5a (patch)
tree78871a7af5860a7d35b167847e8c3b401c352720
parentcb8bcd478129c490a2635d0b938de1e2d7c774d2 (diff)
downloadlua-language-server-0d79784ccf47a03f9f35e1afbd579ecbab0acd5a.zip
fix
-rw-r--r--script/core/diagnostics/unreachable-code.lua3
-rw-r--r--script/parser/guide.lua1
-rw-r--r--test/diagnostics/common.lua14
3 files changed, 17 insertions, 1 deletions
diff --git a/script/core/diagnostics/unreachable-code.lua b/script/core/diagnostics/unreachable-code.lua
index a386198c..84b25b45 100644
--- a/script/core/diagnostics/unreachable-code.lua
+++ b/script/core/diagnostics/unreachable-code.lua
@@ -24,7 +24,8 @@ local function hasReturn(block)
return hasElse == true
else
if block.type == 'while' then
- if vm.testCondition(block.filter) then
+ if vm.testCondition(block.filter)
+ and not block.breaks then
return true
end
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 76f0fbca..d89a1305 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -13,6 +13,7 @@ local type = type
---@field args { [integer]: parser.object, start: integer, finish: integer }
---@field locals parser.object[]
---@field returns? parser.object[]
+---@field breaks? parser.object[]
---@field exps parser.object[]
---@field keys parser.object
---@field uri uri
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 1ab6ec5c..4c065ac6 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1986,3 +1986,17 @@ function X()
<!return true!>
end
]]
+
+TEST [[
+---@diagnostic disable: undefined-global
+
+while true do
+ if not X then
+ break
+ end
+end
+
+print(1)
+
+do return end
+]]