Skip to content

never doesn't do what it's supposed to do #877

Closed

Description

@idanarye

Using version 0.18 downloaded from the GH release:

$ ./emmylua_check --version
emmylua_check 0.18.0

I wrote this file:

---@return integer?
local function create_num()
    return 1
end

---@param _num integer
local function accept_num(_num)
end

---@return never
local function panic()
    error("panic!")
end

local num1 = create_num()
if num1 == nil then
    panic()
end
accept_num(num1)

local num2 = create_num()
if num2 == nil then
    error()
end
accept_num(num2)

And ran:

$ ./emmylua_check .
--- main.lua [1 warning]
warning: expected `integer` but found `integer?`.  [param-type-mismatch]
  -->: main.lua:19:12

  18 │ end
  19 │ accept_num(num1)
  20 │ 



Summary
  1 warning

Check completed with warnings
Check finished

num2 worked as expected - using the builtin error when its nil convinced the type checker that it cannot be nil. But why does it think num1 is still an integer?? I've annotated my panic() as ---@return never, which - in any language that has a never type - means it can never return (either by looping forever, by throwing an error, or by crashing the program itself via whatever means), and therefore the type checker should consider it equivalent to calling error() and conclude the num1 is integer and not integer? after that check. But it doesn't.

Activity

  1. CppCXY commented on Dec 9, 2025

    @CppCXY
    Member

    you can config like:

    {
        "runtime": {
            "special": {
                "panic" : "error"
            },
            "version": "LuaLatest"
        }
    }
    

    In the current control-flow analysis we assume our type analysis is not yet complete, so we can't make use of that information.

  2. idanarye commented on Dec 9, 2025

    @idanarye
    Author

    What's the purpose of the never type, then?

  3. xuhuanzy commented on Dec 9, 2025

    @xuhuanzy
    Member

    never is currently equivalent to nil

  4. xuhuanzy commented on Jun 20, 2026

    @xuhuanzy
    Member

    I think it's now possible to support this issue to a limited extent.

  5. self-assigned this
    on Jun 20, 2026
  6. added theissue type on Jun 20, 2026
  7. added a commit that references this issue on Jun 21, 2026
    c5d947d
  8. xuhuanzy commented on Jun 21, 2026

    @xuhuanzy
    Member

    Added a rough implementation without performing detailed control flow analysis.

  9. added a commit that references this issue on Jun 22, 2026
    bb30692
  10. added a commit that references this issue on Jul 1, 2026
    90b108f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions