-
Notifications
You must be signed in to change notification settings - Fork 53
instantiate generics using the passed functions #9
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
instantiate generics using the passed functions #9
Conversation
|
I hope the solution is acceptable as a temporary one. I've a problematic scenario that's hard to deal with. ---@generic K, V
---@class fun.table_iterator<K, V>
table_iterator_methods = {}
---@generic K, V, W
---@param self fun.table_iterator<K, V>
---@param f fun(a: V): W
---@return fun.table_iterator<K, W>
function table_iterator_methods.map(self, f) end
---@type fun(a:string, b:string): number
local process = function(a, b)
return tostring(b)
end
---@type fun.table_iterator<string, string>
local a = {}
-- The `fun.table_iterator<string, number>` type is not inferred.
-- It's `fun.table_iterator<string, unknown>` instead.
local b = a:map(process)It's impossible yet to infer the type of Thus, currently the algorithm works in this steps. Please, let me now if this is wrong or not. |
This patch bumps `actions/upload-artifact@v3` to `actions/upload-artifact@v4`. Now `v3` is deprecated [^1] which turned out to break EmmyLuaLs#9. [^1] https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/
67233df to
4516222
Compare
This patch bumps `actions/upload-artifact@v3` to `actions/upload-artifact@v4`. Now `v3` is deprecated [^1] which turned out to break EmmyLuaLs#9. [^1] https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/
This patch adds simple type level matching for the doc functions and signatures allowing to instantiate generics based on the passed functions. The following code demonstrates a generic type instantiated by this feature. ```lua ---@param a number ---@return string local function tostr(a) return tostring(a) end ---@Generic T, U ---@param x T ---@param f fun(x: T): U ---@return U local function apply(x, f) return f(x) end --"a" is inferred as a string. a = apply(3, tostr) ```
4516222 to
6151d2e
Compare
|
I have fixed the issue with the generics, you can try the most reasonable way to write it again. |
|
Thank you for an explanation and for working in it. I've changed the return type of process to ---@class fun.table_iterator<K, V>
table_iterator_methods = {}
---@generic W
---@param f fun(a: any): W
---@return fun.table_iterator<K, W>
function table_iterator_methods:map(f) end
---@param a string
---@param b number
---@return table
local function process(a, b)
return {}
end
---@type fun.table_iterator<string, number>
local a = {}
-- b is fun.table_iterator<string, string>, not
-- fun.table_iterator<string, table>
local b = a:map(process)The behavior is the same if you define process using ---@param a string
---@param b number
---@return table
local process = function(a, b)
return {}
endThe syntax suggested by me also ends up with unknown type. |
I roughly understand why — there are two generic parameters from different sources here, both numbered 0. I might need to change the generics to an enum type. I'll fix this after I wake up. |
|
I have fix this issue, please try again |
|
It now works properly. Thank you very much. |


This patch adds simple type level matching for the doc functions and signatures allowing to instantiate generics based on the passed functions.
The following code demonstrates a generic type instantiated by this feature.