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

Operator overloading is not detected properly #1338

Closed
kenzocarneiro opened this issue Jul 16, 2022 · 1 comment
Closed

Operator overloading is not detected properly #1338

kenzocarneiro opened this issue Jul 16, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@kenzocarneiro
Copy link

Describe the bug
When creating a class and overloading its operators, the extension doesn't seem to detect the new return value of the operation. The result is detected as a "number":

--- Class representing Vectors.
--- @class Vector
--- @field x number
--- @field y number
Vector = {}

--- Constructor of Vector.
--- @param x number
--- @param y number
--- @return Vector
function Vector:new(x, y)
    local e = {}
    setmetatable(e, self)
    self.__index = self
    e.x = x or 0
    e.y = y or 0
    return e
end

--- Add to another Vector.
--- @param v Vector
--- @return Vector
function Vector:__add(v)
    return Vector:new(self.x + v.x, self.y + v.y)
end

local v = Vector:new(3, 4)
v = v + Vector:new(1, 2) --- Warning here
print(v)

The __add function is detected:
image

But there is still a warning:
image

This may be related to #599, but I'm not sure.

To Reproduce
Create a class and overload the operators. (See the code above).

Expected behavior
This shouldn't trigger a warning: since __add is documented, the result of the operation should be detected as a Vector (or at least an "any" for a sum/div/... with tables).

Environment:

  • OS: Windows 10 x64
  • Is WSL remote? No
  • Client: VSCode
@sumneko
Copy link
Collaborator

sumneko commented Jul 16, 2022

Same as #599

@sumneko sumneko closed this as completed Jul 16, 2022
@sumneko sumneko added the duplicate This issue or pull request already exists label Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants