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

Duplicate functions should act like overload #1354

Closed
FlashHit opened this issue Jul 19, 2022 · 3 comments
Closed

Duplicate functions should act like overload #1354

FlashHit opened this issue Jul 19, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@FlashHit
Copy link

We have this inside a library:

---@class Guid
local Guid

---@class DataContainer
local DataContainer = {}

---`SERVER/CLIENT`
---Creates a shallow clone of this instance, which is essentially the equivalent of creating a new instance of the same type and assigning the values of this instance to all of its properties. Any properties that contain structure types (eg. Vec3) will be cloned when assigning, while properties that contain instance types (eg. DataContainer) will be referencing the same instance.
---@return DataContainer @ The newly created instance.
function DataContainer:Clone() end

---`SERVER/CLIENT`
---Creates a shallow clone of this instance and assigns it the provided Guid, which is essentially the equivalent of creating a new instance of the same type with the provided Guid and assigning the values of this instance to all of its properties. Any properties that contain structure types (eg. Vec3) will be cloned when assigning, while properties that contain instance types (eg. DataContainer) will be referencing the same instance.
---@param guid Guid @ The Guid to assign to the cloned instance.
---@return DataContainer @ The newly created instance.
function DataContainer:Clone(guid) end

---@type DataContainer
local s

---@type Guid
local t

s:Clone(t)

grafik

It's correct to show that this is a duplicate function. But it should not ignore the second one. Instead it should act like an overload.

@Feez
Copy link

Feez commented Jul 19, 2022

You should just use the EmmyLua (or LuaDoc?) ---@overload syntax as far as documentation. It doesn't make much sense to define a function twice and expect the language server to treat it as overloads as far as normal Lua, however.

i.e:

  ---@overload fun(x: number, y: number):string
  ---@overload fun(x: number):number
  ---@return boolean
  local function f() end

@FlashHit
Copy link
Author

well its a library that does that not me. Don't feel like changing thousand of files.

@carsakiller
Copy link
Collaborator

The other problem with the @overload tag is it does not allow you to provide a description for the function or its parameters. I often write my documentation in this same way where there are two functions with differing annotations - which results in some weirdness with the intellisense.

@sumneko sumneko added the bug Something isn't working label Jul 20, 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
Projects
None yet
Development

No branches or pull requests

4 participants