Replies: 3 comments 4 replies
-
|
If you put your code into a function and add a return after the I hope that can help in your use case. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
4 replies
-
|
For the very specific case of OP, we can use the
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"runtime.special": {
"custom_error": "error"
}
}
---@class Foo
---@field bar number
---@return Foo?
local function get_foo()
return nil
end
local function custom_error()
error()
end
---@return number
local function get_bar_with_custom_error()
local foo = get_foo()
if foo == nil then
custom_error()
end
return foo.bar --> `Foo.bar: number`
-- instead of `Foo|nil.bar: number` which triggers nil check error
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Uh oh!
There was an error while loading. Please reload this page.
-
Say I have something like this:
LuaLS complains that I've accessed

foo.bareven thoughfoocould benil:But if I use the builtin

errorinstead of mycustom_error, LuaLS knows that this point cannot be reached whenfooisnil:Is there a way to annotate
custom_errorso that LuaLS will know that it never returns, just like the builtinerror?Beta Was this translation helpful? Give feedback.
All reactions