It seems assert() breaks after asserting a method defined further down in the file. The returned type from assert() after that point becomes ().
--- @namespace assert_with_method_defined_later
--- @class Foo
local Foo = {}
--- @type string?
local nullable_string
--- @return boolean
function Foo:defined_before() return false end
function Foo:main()
local _v1 = assert(nullable_string)
-- ^ type: `string` ✅
assert(self:defined_before())
local _v2 = assert(nullable_string)
-- ^ type: `string` ✅
assert(self:defined_later())
local _v3 = assert(nullable_string)
-- ^ type: `()` ❌
end
--- @return boolean
function Foo:defined_later() return false end
Curiously it works if the returned value from the assert is assigned to a variable:
--- @namespace assert_with_method_defined_later
--- @class Foo
local Foo = {}
--- @type string?
local nullable_string
function Foo:main()
local _ = assert(self:defined_later())
local _v1 = assert(nullable_string)
-- ^ type: `string` ✅
end
--- @return boolean
function Foo:defined_later() return false end
Reproduced on 0.22.0 and 2f9cb6d.
It seems
assert()breaks after asserting a method defined further down in the file. The returned type fromassert()after that point becomes().Curiously it works if the returned value from the assert is assigned to a variable:
Reproduced on
0.22.0and 2f9cb6d.