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

feature: support generics in function type format

Open TheFireBlast opened this issue 3 years ago • 3 comments

Currently, the only way to document generic functions is to use @generic. and it's not possible to use them in overloads or fields.

The following examples are invalid:

---@generic T
---@param arg1 string
---@param arg2 T
---@return T
---@overload fun(arg2: T) <- Undefined type or alias `T`.
local function foo(arg1, arg2)
    return arg2 or arg1
end
---@class Foo
---@field bar fun<T>(arg:T): T <- `(` expected.
local Foo = {}

TheFireBlast avatar May 26 '22 01:05 TheFireBlast

#723 seems like it already covers this?

stylpe avatar Mar 21 '23 21:03 stylpe

+1, porting Haskell's ReadP to Lua and I need a fun<U>(fun(T): P<U>): P<U>.

PoolloverNathan avatar Apr 14 '24 15:04 PoolloverNathan

T should also be visible inside function body

---@generic T
---@param list? T[]
local function foo(list)
  ---@cast list T[] -- warning: Undefined type or alias `T`.
end

sharpchen avatar May 23 '25 10:05 sharpchen