moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

continue statement usage with return statement causes a syntax error

Open xiaoandtell opened this issue 11 months ago • 0 comments

Moonscript (main.lua):

-- print the first number divisible by 4
foo = () ->
	for i = 0, 40
		continue if not (i % 4 == 0)
		print i
		return
foo()

Compiled Lua:

foo = function()
  for i = 0, 40 do
    local _continue_0 = false
    repeat
      if not (i % 4 == 0) then
        _continue_0 = true
        break
      end
      print(i)
      return 
      _continue_0 = true
    until true
    if not _continue_0 then
      break
    end
  end
end
return foo()

error:

Error
Syntax error: main.lua:12: 'until' expected (to close 'repeat' at line 5) near '='
Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: at 0x7ffc25e62fa0
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

xiaoandtell avatar Jan 13 '25 03:01 xiaoandtell