Skip to content

Commit 4e616bb

Browse files
committed
fix: ignore function's auto infer type when there is only @overload
1 parent c9d8193 commit 4e616bb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

script/vm/function.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ end
359359
---@return number
360360
local function calcFunctionMatchScore(uri, args, func)
361361
if vm.isVarargFunctionWithOverloads(func)
362+
or vm.isFunctionWithOnlyOverloads(func)
362363
or not isAllParamMatched(uri, args, func.args)
363364
then
364365
return -1
@@ -490,6 +491,36 @@ function vm.isVarargFunctionWithOverloads(func)
490491
return false
491492
end
492493

494+
---@param func table
495+
---@return boolean
496+
function vm.isFunctionWithOnlyOverloads(func)
497+
if func.type ~= 'function' then
498+
return false
499+
end
500+
if func._onlyOverloadFunction ~= nil then
501+
return func._onlyOverloadFunction
502+
end
503+
504+
if not func.bindDocs then
505+
func._onlyOverloadFunction = false
506+
return false
507+
end
508+
local hasOverload = false
509+
for _, doc in ipairs(func.bindDocs) do
510+
if doc.type == 'doc.overload' then
511+
hasOverload = true
512+
elseif doc.type == 'doc.param'
513+
or doc.type == 'doc.return'
514+
then
515+
-- has specified @param or @return, thus not only @overload
516+
func._onlyOverloadFunction = false
517+
return false
518+
end
519+
end
520+
func._onlyOverloadFunction = hasOverload
521+
return true
522+
end
523+
493524
---@param func parser.object
494525
---@return boolean
495526
function vm.isEmptyFunction(func)

0 commit comments

Comments
 (0)