diff options
-rw-r--r-- | script/core/diagnostics/unreachable-code.lua | 3 | ||||
-rw-r--r-- | script/parser/guide.lua | 1 | ||||
-rw-r--r-- | test/diagnostics/common.lua | 14 |
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 +]] |