LuaLS / LuaLS/lua-language-server

关于泛型函数

Open
#2,501 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

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

使用---@generic T:frame ---@return T
获取到的返回类型好像没办法继承到frame?
fun(T):T 这种写法好像不生效,有什么类似的写法吗

Actual Behaviour

QQ截图20240128083839

fun里好像没有办法写泛型

Reproduction steps

---@generic T:frame
---@overload fun(name:T):fun(params:table):frame.T
local newframe = setmetatable({},{
__index = frame,
__call = function(self,name)
local class = rawget(self,name)
if class and getmetatable(class) then
return function(param)
return frame(class,param)
end
end
end,
})

---@type frame.button
local a = newframe 'button' {

}

Additional Notes

有什么格式支持这种返回值吗

Log File

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generic annotation and setmetatable reproduction in the issue, then trace how the type checker handles ---@generic, ---@overload, and fun return types. Done means either the existing annotation format correctly infers frame.button or the supported syntax and its limitations are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.