Skip to content

Unexpected generic behaviour #3125

@Frityet

Description

@Frityet

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Annotations

Expected Behaviour

local ffi = require("ffi")

---@generic T
---@param ct `T`
---@return fun(x: T): `T`*
local function ref(ct)
    return function (init)
        return ffi.new(ct.."[1]", {init})
    end
end

ffi.cdef [[
    typedef struct MyStruct {
        int a, b;
    } MyStruct;
]]

---@class MyStruct
---@field a integer
---@field b integer

---@class MyStruct* : { [integer] : MyStruct }, ffi.cdata*

local x = ffi.ref "MyStruct" {
    a = 4,
    b = 2
}

--type of `x` expected to be `MyStruct*`

Actual Behaviour

type of x is MyStruct

Reproduction steps

Run the code and check types

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