Skip to content

Returning a custom class with a generic parameter causes unknown behaviour #3019

@Joakker

Description

@Joakker

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

When defining a file like

---@class Promise
Promise = {}

---@generic T
---@param func fun(value: T)
function Promise:and_then(func) end

---@param entity integer
---@return Promise<string?>
function get_name(entity) end

local name_promise = get_name(1)

The LSP should be able to tell that name is of type Promise<string?>

Actual Behaviour

The LSP is able to identify the type of name, however, it doesn't show the fields/methods of the class, and it doesn't infer anything about it either, ie, building from the example above

name:and_then(
    function(value)
        print(value)
    end
)

The LSP should be able to infer that value should be of type string?

Reproduction steps

Simply type in the code as shown above

Additional Notes

No response

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    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