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

Function Prototype Narrowing with nils

Open Rathoz opened this issue 1 year ago • 2 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

Foo.Bar('Baz', 'Qux') -- **string**
Foo.Bar('Baz', nil) -- nil
Foo.Bar('Baz') -- nil
Foo.Bar(nil, 'Qux') -- nil
Foo.Bar(nil, nil) -- nil
Foo.Bar() -- nil

Actual Behaviour

Foo.Bar('Baz', 'Qux') -- **string|nil**
Foo.Bar('Baz', nil) -- nil
Foo.Bar('Baz') -- nil
Foo.Bar(nil, 'Qux') -- nil
Foo.Bar(nil, nil) -- nil
Foo.Bar() -- nil

Reproduction steps

---@param baz string|number
---@param qux string|number
---@return string
---@overload fun(text: string|number, title: nil):nil
---@overload fun(text: nil, title: string|number):nil
---@overload fun(text: nil, title: nil):nil
function Foo.Bar(baz, qux)
	if not baz or not qux then
		return nil
	end
	return 'SomeString'
end

Additional Notes

It seems to match the 'strings' can be nil

First input example image

Last input example image

Log File

No response

Rathoz avatar Jun 12 '24 14:06 Rathoz