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

Issue with generic parameters in 3.6 #1676

Closed
firas-assaad opened this issue Nov 8, 2022 · 1 comment
Closed

Issue with generic parameters in 3.6 #1676

firas-assaad opened this issue Nov 8, 2022 · 1 comment
Labels
bug Something isn't working feat/generic Related to generic emulation feature feat/type check Related to the type checking feature

Comments

@firas-assaad
Copy link
Contributor

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?

Annotations, Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

image

Actual Behaviour

image

Reproduction steps

---@generic T
---@param arr T[]
---@param val? T|(fun(e : T) : boolean)
---@return T? element
local function find(arr, val)
    return arr[1]
end

local arr = { 'a', 'b' }
find(arr, 'b')

Additional Notes

Not sure if my annotations are wrong, but it worked in the previous version. If I change the signature so that the second parameter is T instead of T|fun(e : T) : boolean then it works fine.

---@generic T
---@param arr T[]
---@param val? T
---@return T? element
local function find(arr, val)

Thanks for your continued work on the language server!

Log File

Let me know if you need it.

@sumneko sumneko added bug Something isn't working feat/type check Related to the type checking feature feat/generic Related to generic emulation feature labels Nov 8, 2022
@firas-assaad
Copy link
Contributor Author

Not sure if this usage of generics is supported, but I have a similar issue here as well:

---@generic T
---@param v1 T
---@param v2 T|table
local function func(v1, v2)
end

func('hello', {}) -- works
func('hello', 'world') -- param-type-mismatch, cannot assign string to table|<T>

@sumneko sumneko closed this as completed in e7f8bc7 Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat/generic Related to generic emulation feature feat/type check Related to the type checking feature
Projects
None yet
Development

No branches or pull requests

2 participants