From 97d85952f66b772c255a8856c0cbffa4ef11f1f0 Mon Sep 17 00:00:00 2001 From: Tom Lau Date: Wed, 17 Jul 2024 15:07:21 +0800 Subject: [PATCH] fix: inconsistent type narrow due to outdated node caches of call.args --- changelog.md | 1 + script/vm/compiler.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/changelog.md b/changelog.md index a82efdabe..c62510abf 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ * `NEW` added lua regular expression support for Lua.doc.Name [#2753](https://github.com/LuaLS/lua-language-server/pull/2753) * `FIX` Bad triggering of the `inject-field` diagnostic, when the fields are declared at the creation of the object [#2746](https://github.com/LuaLS/lua-language-server/issues/2746) * `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer` +* `FIX` Inconsistent type narrow behavior of function call args [#2758](https://github.com/LuaLS/lua-language-server/issues/2758) ## 3.9.3 `2024-6-11` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e1b1b43b8..f3655123f 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -575,6 +575,12 @@ local function matchCall(source) newNode:removeNode(needRemove) newNode.originNode = myNode vm.setNode(source, newNode, true) + 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) + end + end end end