Skip to content

Commit

Permalink
fix runtime error
Browse files Browse the repository at this point in the history
fix #2776
  • Loading branch information
sumneko committed Aug 2, 2024
1 parent bf69b7c commit 8ecec08
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->

## 3.10.1
* `FIX` Runtime error

## 3.10.0
`2024-8-1`
* `NEW` Add postfix snippet for `unpack`
Expand Down
12 changes: 11 additions & 1 deletion script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,17 @@ local function matchCall(source)
if call.args then
-- clear node caches of args to allow recomputation with the type narrowed call
for _, arg in ipairs(call.args) do
vm.removeNode(arg)
vm.setNode(arg, vm.createNode(), true)
end
for n in newNode:eachObject() do
if n.type == 'function'
or n.type == 'doc.type.function' then
for i, arg in ipairs(call.args) do
if n.args[i] then
vm.setNode(arg, vm.compileNode(n.args[i]))
end
end
end
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions test/type_inference/param_match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,27 @@ local function f(...) end
local <?r?> = f(10)
]]

TEST 'number' [[
---@overload fun(a: 1, c: fun(x: number))
---@overload fun(a: 2, c: fun(x: string))
local function f(...) end
f(1, function (<?a?>) end)
]]

TEST 'string' [[
---@overload fun(a: 1, c: fun(x: number))
---@overload fun(a: 2, c: fun(x: string))
local function f(...) end
f(2, function (<?a?>) end)
]]

TEST 'any' [[
---@overload fun(a: 1)
---@overload fun(a: 2)
local function f(...) end
f(1, function (<?a?>) end)
]]

0 comments on commit 8ecec08

Please sign in to comment.