summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorTom Lau <tomandfatboy@gmail.com>2024-09-06 10:57:50 +0800
committerTom Lau <tomandfatboy@gmail.com>2024-09-07 10:37:23 +0800
commit9794cc44b6524f0d3bc4e0bab59275745802366b (patch)
tree3b22e125ec6d2387e62d31c3cc4ef196caceb744 /script
parent4e616bb1f773b430f1997ec675f8336ad8f1803b (diff)
downloadlua-language-server-9794cc44b6524f0d3bc4e0bab59275745802366b.zip
fix: function param's auto infer type should use union of all overload
Diffstat (limited to 'script')
-rw-r--r--script/vm/compiler.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 041d287e..50f260c2 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1099,6 +1099,7 @@ local function compileFunctionParam(func, source)
-- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
local funcNode = vm.compileNode(func)
+ local found = false
for n in funcNode:eachObject() do
if n.type == 'doc.type.function' and n.args[aindex] then
local argNode = vm.compileNode(n.args[aindex])
@@ -1107,9 +1108,16 @@ local function compileFunctionParam(func, source)
vm.setNode(source, an)
end
end
- return true
+ -- NOTE: keep existing behavior for local call which only set type based on the 1st match
+ if func.parent.type == 'callargs' then
+ return true
+ end
+ found = true
end
end
+ if found then
+ return true
+ end
local derviationParam = config.get(guide.getUri(func), 'Lua.type.inferParamType')
if derviationParam and func.parent.type == 'local' and func.parent.ref then