-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels