Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning generics with T<X, Y> #1000

Open
Cassolette opened this issue Mar 25, 2022 · 2 comments
Open

Returning generics with T<X, Y> #1000

Cassolette opened this issue Mar 25, 2022 · 2 comments
Labels
enhancement New feature or request feat/generic Related to generic emulation feature feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)

Comments

@Cassolette
Copy link
Contributor

Cassolette commented Mar 25, 2022

Below, I have a generic list that uses fluid interface to return itself for some methods:

--- @class List
local List = {}

--- @generic T : List, V, _
--- @param self T<V, _>
--- @param value V         # Element value to insert
--- @return T<V, _>        # Returning itself (a generic)
function List:insert(value)
    return self           -- Returning itself (a generic)
end

-- test
---@type List<number, nil>
local mylist

local testingType = mylist:insert(1)
-- ^ Testing type is not `List<number, nil>` but literally `T<V, _>`

image

Expected behavior
testingType is of type List<number, nil>

I am thinking that this case could be something to look at for the 3.0 update.

(Edit: perfect #1000th issue...)

@Cassolette
Copy link
Contributor Author

Cassolette commented Mar 25, 2022

I think a related issue is with parsing the generic syntax in ---@param tbl T<K, V> - K and V are assigned a type except for T

---@generic T : table, K, V
---@param tbl T<K, V>
---@return T
local function Test(tbl)
end

-- testing
---@type table<number, string>
local tableWithGenerics

local shouldBeTableType = Test(tableWithGenerics)
-- ^ is type `any`

Another issue is that --- @return does not support ---@return T<K, V> or even ---@return V[] (Probably only accepts ---@return V alone)

@Cassolette Cassolette changed the title Returning generics Returning generics with T<X, Y> Mar 25, 2022
@sumneko sumneko added enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) labels Mar 25, 2022
@sumneko
Copy link
Collaborator

sumneko commented Apr 14, 2022

  • generic method
  • generic return

@carsakiller carsakiller added the feat/generic Related to generic emulation feature label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat/generic Related to generic emulation feature feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Projects
None yet
Development

No branches or pull requests

3 participants