### 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 ```lua ---@class Iter ---@operator call:number? local iter for i in iter do end -- 'i' should be 'number' ``` ### Actual Behaviour ```lua ---@class Iter ---@operator call:number? local iter for i in iter do end -- 'i' is 'unknown' ``` ### Reproduction steps 1. copy the code above into IDE 2. hover the mouse over the var `i` ### Additional Notes 原因是luals在构造迭代器节点时,只对第一个表达式使用getReturn,而后者只能用来得到函数的返回类型。后续未处理__call的情况,导致除了函数之外的所有callable都被忽略。 ### Log File _No response_
Activity
Issues-translate-bot commentedon Sep 19, 2026
Title: The type deduction of the generic for iterator misses the class with __call
tomlau10 commentedon Sep 20, 2026
我印象中
@operator call有很多功能還未有實裝按 maintainer 建議是用
@overload fun():...#2143 (comment)
現狀來說可以寫成如下
blanhhy commentedon Sep 20, 2026
@tomlau10 我知道这样能行。但是也有不太适用的情况,比如假如是这种情形:
@overload会给它联合一个函数类型,然后阻碍多态tomlau10 commentedon Sep 21, 2026
確實會出現以下 error
感覺上是另外的 bug,因為 error msg 中是說
unknowncannot matchIter而不是說functioncannot matchIter? 🤔我試到的 workaround (當然你或許也會認為未必適合)
我項目的
.luarc.json一般還會打開"type.weakUnionCheck": true=> 只要傳入的 param 其中1個 type 滿足 function param 要求,就不會報
param-type-mismatchhttps://luals.github.io/wiki/settings/#typeweakunioncheck
另1個 workaround: 考慮將
---@class Iter也繼承function試了這個情況下不會報錯
---@class Iter: functiontakeIter的 function param annotation 增加 function typeblanhhy commentedon Sep 21, 2026
这个呢,貌似和缓存污染有关...我没有深究也不确定。而且看起来是
@class+@overload组合会出现的特有问题,如果都用@type的话是正常的:给形参或实参标
function或多或少都会导致其他地方出问题。打开
"type.weakUnionCheck": true也许确实是个好办法(因为印象中在别的场景下也有联合类型检查被烦到...)。不过,我暂时在使用补丁,能很好的解决眼下的问题。
for_call_operator.lua
但是还是希望修复能进入到luals本身啊。