lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Support for a bottom type for non-returning functions

Open emmericp opened this issue 1 year ago • 1 comments

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

Have a way to tag the return type of a function as Bottom, i.e., never returns.

Actual Behaviour

I have a snippet like this:


local function abort(err)
	io.stderr:write(err .. "\n")
	os.exit(1)
end

local function stuff()
	local chunk = loadfile("x.lua")
	if not chunk then
		abort("failed to loadfile()")
	end
	chunk()
	return {}
end

stuff()

which triggers the "need-nil-check" diagnostic on "chunk()" because it doesn't understand that abort() never returns, so i would like to tag abort() (or better tag os.exit() and do return os.exit) as never returning function.

obvious work-around is to do "return abort(...)" instead, but that messes up the return type of stuff() from table to table|nil. so i have to write abort() return {} to make the type checker happy which is a bit cumbersome

Reproduction steps

  1. Go to '...'
  2. Click '...'
  3. See error '...'

Additional Notes

No response

Log File

No response

emmericp avatar Dec 10 '23 13:12 emmericp

See https://github.com/LuaLS/lua-language-server/issues/1881 for a similar request.

firas-assaad avatar Dec 10 '23 18:12 firas-assaad