IntelliJ-EmmyLua icon indicating copy to clipboard operation
IntelliJ-EmmyLua copied to clipboard

Improve Method Override support for tables with known types

Open pouwelsjochem opened this issue 4 years ago • 1 comments

Environment(环境)

name version
IDEA version 2020.2.4
EmmyLua version 1.3.4
OS MacOS 10.15.7

What are the steps to reproduce this issue?(重现步骤?)

The following code can be used:

local t = {}

function t:new()
    local class = {} ---@class myClass

    ---@param _numberParam number
    function class:method(_numberParam)
        -- EmmyLua does know _numberParam is a number
    end

    return class
end

local classInstance1 = t:new() ---@type myClass
function classInstance1:method(_numberParam)
    -- EmmyLua does NOT know _numberParam is a number
end

local classInstance2 = t:new() ---@class myClassInstance : myClass
function classInstance2:method(_numberParam)
    -- EmmyLua does know _numberParam is a number
end

What happens?(出现什么问题?)

After overriding an instance method, EmmyLua only keeps parameter information when the instance is defined as a new class.

What were you expecting to happen?(期望?)

EmmaLua to understand parameter information after overriding a instance method with known type information. So referring to the code example, it would be great if it would work on classInstance1

pouwelsjochem avatar Dec 01 '20 12:12 pouwelsjochem

It does seem to work when myClass has another parent where the method is initially defined. I guess EmmyLua only defines it as an override when it's a named subclass, which makes sense. Although I would love to be able to create anonymous subclasses as well, perhaps with a new annotation? @subclassOf myClass / @extends myClass ?

local t = {}

function t:newParent()
    local class = {} ---@class myClassParent

    ---@param _numberParam number
    function class:method(_numberParam)
        -- EmmyLua does know _numberParam is a number
    end

    return class
end

function t:new()
    local class = {} ---@class myClass : myClassParent

    return class
end

local classInstance1 = t:new() ---@type myClass
function classInstance1:method(_numberParam)
    -- EmmyLua does know _numberParam is a number
end

local classInstance2 = t:new() ---@class myClassInstance : myClass
function classInstance2:method(_numberParam)
    -- EmmyLua does know _numberParam is a number
end

pouwelsjochem avatar Dec 03 '20 16:12 pouwelsjochem