Skip to content

Commit 9794cc4

Browse files
committed
fix: function param's auto infer type should use union of all overload
1 parent 4e616bb commit 9794cc4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

script/vm/compiler.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ local function compileFunctionParam(func, source)
10991099

11001100
-- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
11011101
local funcNode = vm.compileNode(func)
1102+
local found = false
11021103
for n in funcNode:eachObject() do
11031104
if n.type == 'doc.type.function' and n.args[aindex] then
11041105
local argNode = vm.compileNode(n.args[aindex])
@@ -1107,9 +1108,16 @@ local function compileFunctionParam(func, source)
11071108
vm.setNode(source, an)
11081109
end
11091110
end
1110-
return true
1111+
-- NOTE: keep existing behavior for local call which only set type based on the 1st match
1112+
if func.parent.type == 'callargs' then
1113+
return true
1114+
end
1115+
found = true
11111116
end
11121117
end
1118+
if found then
1119+
return true
1120+
end
11131121

11141122
local derviationParam = config.get(guide.getUri(func), 'Lua.type.inferParamType')
11151123
if derviationParam and func.parent.type == 'local' and func.parent.ref then

0 commit comments

Comments
 (0)