Skip to content

Feature Request: Add @not_return annotation to indicate functions never return (like Python's NoReturn) #1230

Description

@Erlonealpha

description

I would like to request a new annotation, @not_return, to explicitly mark a function that never returns normally. This would be similar to Python's NoReturn type hint or C++'s [[noreturn]] attribute.

Use Case

In Lua, it's common to have helper functions for error handling, such as a custom raise function:

---@param msg string
---@not_return
function raise(msg)
    error(msg)
end

function foo(input)
    if not input then
        raise("input is nil")  -- This call never returns
    end
    -- The analyzer should understand that code after this point is unreachable if the condition is met
    return input
end

Proposed Behavior

  • A function annotated with @not_return should be treated by the analyzer as a function that never successfully returns to its caller.
  • The analyzer should use this information to:
    • Suppress diagnostics (like "missing return") on subsequent code paths where the only exit is a call to such a function.
    • (Potentially) Identify and warn about unreachable code that follows such a call unconditionally.

Additional Context

  • This would be analogous to EmmyLua's @return annotation but for the absence of a return.
  • It could be very useful for the emmylua_check linter to provide more accurate static analysis.
    Thank you for considering this feature request!

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