LuaLS / LuaLS/lua-language-server

---@class with function return question

未关闭
#2,602 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

so I have this (as a mockup):

do
    ---@class a
    local a = {}

    ---@generic T
    ---@param self a
    ---@param new T
    ---@return T
    a.extend = function(self, new)
        --...
        return new
    end
end

and it's supposed to be inheritance for prototypes, right, but I'm trying to make the LS think that it returns the second parameter new and it does that and the LS thinks that, so far so good. So this

    local b = a:extend{
        n = 1
    }

will make it like this:
p1
but the problem is, that if I use ---@class b here, then it will ignore what the function returns and I get this:
p2
am I missing something or is it just not possible? Though, if I separate it into two statements like this,

    ---@class b
    local b = {
        n = 1
    }

    b = a:extend(b)

then I get what I want:
p3
but it's not ideal, since it's two statements now and I can't use the fun{} syntactic sugar this way, which would be the whole reason, right. Is there a way to make it work? Also I'm unsure about how to properly word the title here

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定源文件或测试。复现两个单行 Lua 代码片段和两个双语句 Lua 代码片段,然后跟踪 LuaLS 对局部声明、类注解、泛型和函数返回值的类型推断。实现受支持的行为并由回归测试覆盖,或明确记录该限制,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。