diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-08-02 16:33:06 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2024-08-02 16:33:06 +0800 |
commit | 8ecec087ee48501252699b2759b00056db6ef298 (patch) | |
tree | fa7580d5ee7fa3c39e3771d73d0912c6c7e6e137 | |
parent | bf69b7c7f6875559e988868c2f2a46d5c670f690 (diff) | |
download | lua-language-server-8ecec087ee48501252699b2759b00056db6ef298.zip |
fix runtime error
fix #2776
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/vm/compiler.lua | 12 | ||||
-rw-r--r-- | test/type_inference/param_match.lua | 24 |
3 files changed, 38 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 61193793..94cf4a1c 100644 --- a/changelog.md +++ b/changelog.md @@ -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` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index f3655123..54390450 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -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 diff --git a/test/type_inference/param_match.lua b/test/type_inference/param_match.lua index 8ead05ef..1079e433 100644 --- a/test/type_inference/param_match.lua +++ b/test/type_inference/param_match.lua @@ -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) +]] |