Fix incorrect function params' type infer when there is only @overload
#2838
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #2509, fix #2708, fix #2709
(this logic has to be based on #2822, otherwise might cause other issues in type narrow behavior)
Promblem
When a function only has
@overload
annotation, the function itself will auto infer its params' type by using only the 1st overload type, combined with the return type of the function body logic, thus create an incorrect base function when doing function match.Minimal Example
Proposed Solution
Just ignore the baseline function type when it is annotated with only
@overload
.In case the function has at least one
@param
or@return
, then keep the existing behavior.Expected Result
中文版
這個其實是 #2822 的延續,上次說怕一次改太多會出 bug,所以拆分 PR
當前在一個 function 只有
@overload
的情況下,這 function 的 type 會直接從 第一個 overload 獲取更甚者是還會結合 function body logic 自身的 return type (在寫
@meta
時很大可能是nil
,因為是 empty function body)return nil
也當成一種 union return type這裡解決方式是當 function 只有
@overload
時,就忽略這個 baseline function type,只從 overload 中做 match有如當 function 是單純
local f(...)
全 vararg 時就直接忽略反過來說如果 function 有至少1個
@param
或@return
=> 維持現有 behavior應該也是需要 @sumneko 來 review