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

mix class and type issue #1055

Closed
sumneko opened this issue Apr 14, 2022 · 4 comments
Closed

mix class and type issue #1055

sumneko opened this issue Apr 14, 2022 · 4 comments
Labels
enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)

Comments

@sumneko
Copy link
Collaborator

sumneko commented Apr 14, 2022

I have some issue here:

---@class Foo
---@field f number
---@type fun(self: Foo, ...): Foo
local Foo = setmetatable({}, {
    __call = function(self)
        return self
    end
})

function Foo.new()
end

function Foo:doSomething()
    return self.f -- Undefined field `f`. 
end

Originally posted by @kevinhwang91 in #1050 (comment)

@sumneko sumneko added bug Something isn't working enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) and removed bug Something isn't working labels Apr 14, 2022
@sumneko
Copy link
Collaborator Author

sumneko commented Apr 14, 2022

In version 3.0, I strictly set that only the last ---@class / ---@type will affect the code.

You need to change the line 3 to ---@type Foo | fun(self: Foo, ...): Foo

@kevinhwang91
Copy link
Contributor

---@class Foo
---@field f number

---@type Foo|fun(self: Foo): Foo
local Foo = setmetatable({}, {
    __call = function(self)
        return self
    end
})

Foo.__index = Foo

---@return Foo
function Foo.new()
    local o = {}
    setmetatable(o, Foo)
    return o
end

function Foo:doSomething()
    return self.f
end

function Foo.build()
    local o = Foo.new()
    o:doSomething()  -- Undefined field `doSomething`.
end

Complain Undefined field doSomething at o:doSomething() . I must delete the empty line at line 3.

How can I make the Foo be regarded as Class in semantictoken? For now, it become as Function.

@sumneko
Copy link
Collaborator Author

sumneko commented Apr 15, 2022

I can support ---@overload under ---@class

@sumneko sumneko closed this as completed Jun 30, 2022
@sumneko
Copy link
Collaborator Author

sumneko commented Jun 30, 2022

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Projects
None yet
Development

No branches or pull requests

2 participants