File tree Expand file tree Collapse file tree 4 files changed +43
-2
lines changed
Expand file tree Collapse file tree 4 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ local type = type
5959--- @field filter parser.object
6060--- @field hasGoTo ? true
6161--- @field hasReturn ? true
62+ --- @field hasBreak ? true
6263--- @field _root parser.object
6364
6465--- @class guide
Original file line number Diff line number Diff line change @@ -3606,6 +3606,15 @@ local function parseBreak()
36063606 break
36073607 end
36083608 end
3609+ for i = # Chunk , 1 , - 1 do
3610+ local chunk = Chunk [i ]
3611+ if chunk .type == ' ifblock'
3612+ or chunk .type == ' elseifblock'
3613+ or chunk .type == ' elseblock' then
3614+ chunk .hasBreak = true
3615+ break
3616+ end
3617+ end
36093618 if not ok and Mode == ' Lua' then
36103619 pushError {
36113620 type = ' BREAK_OUTSIDE' ,
Original file line number Diff line number Diff line change @@ -193,7 +193,8 @@ function mt:_compileBlock(block)
193193 self .steps [# self .steps + 1 ] = blockStep
194194 self :_compileNarrowByFilter (childBlock .filter , outStep , blockStep )
195195 if not childBlock .hasReturn
196- and not childBlock .hasGoTo then
196+ and not childBlock .hasGoTo
197+ and not childBlock .hasBreak then
197198 finals [# finals + 1 ] = blockStep
198199 end
199200 self .steps [# self .steps + 1 ] = {
@@ -212,7 +213,12 @@ function mt:_compileBlock(block)
212213 end
213214 end
214215
215- if block .type == ' function' then
216+ if block .type == ' function'
217+ or block .type == ' while'
218+ or block .type == ' loop'
219+ or block .type == ' in'
220+ or block .type == ' repeat'
221+ or block .type == ' for' then
216222 self .steps [# self .steps + 1 ] = {
217223 type = ' load' ,
218224 pos = block .start ,
Original file line number Diff line number Diff line change @@ -2023,3 +2023,28 @@ end
20232023
20242024print(<?x?>)
20252025]]
2026+
2027+ TEST ' integer' [[
2028+ ---@type integer?
2029+ local x
2030+
2031+ while true do
2032+ if not x then
2033+ break
2034+ end
2035+ print(<?x?>)
2036+ end
2037+ ]]
2038+
2039+ TEST ' integer?' [[
2040+ ---@type integer?
2041+ local x
2042+
2043+ while true do
2044+ if not x then
2045+ break
2046+ end
2047+ end
2048+
2049+ print(<?x?>)
2050+ ]]
You can’t perform that action at this time.
0 commit comments