Skip to content

wrong duplicate fields when set in metatable #566

Closed
@lewis6991

Description

@lewis6991

Image

--- @class B
--- @field is_finished fun(_): boolean
--- @field wait fun(_, callback: function)

--- @class A
local A = {}

function A:wait(callback)
  callback()
end

--- @return boolean
function A:is_finished()
  return true
end

--- @return B
function A:foo(...)
  --- @type B
  return setmetatable({
    is_finished = self.is_finished,
    wait = self.wait,
  })
end

The errors are avoided by doing:

--- @return B
function A:foo(...)
  --- @type B
  return setmetatable({
    is_finished = function(_)
      return self:is_finished()
    end,
    wait = function(_, ...)
      return self:wait(...)
    end,
  })
end

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions