Skip to content

[Feature Request] add a warning for goto's that jump across local variable definitions #98

@dljsjr

Description

@dljsjr

I frequently use goto continue with a ::continue:: label as a proxy for Lua's lack of a first-class continue keyword and I often find myself getting bit by jumping over a local variable declaration that doesn't go out of scope; easy enough to fix by introducing do ... end blocks.

Could be a nice warning/lint/error to be able to see via Luacheck.

Here's an extremely simple self contained example:

🐧 ❯ cat init.lua
function bad_goto_loop()
  while true do
    goto continue
    local some_var = "foo"
    ::continue::
    print("loop end, starting again")
  end
end

🐧 ❯ lua init.lua
lua: init.lua:6: <goto continue> at line 3 jumps into the scope of local 'some_var'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions