From b93e0756cc07d9188a8047438f502ff296d5ec66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 30 Jan 2023 20:20:28 +0800 Subject: [PATCH] copy nodes when tracing list fix #1841 --- changelog.md | 2 ++ script/vm/tracer.lua | 4 ++-- test/diagnostics/type-check.lua | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index bf14766f0..d90989914 100644 --- a/changelog.md +++ b/changelog.md @@ -4,9 +4,11 @@ * `NEW` command `lua.exportDocument` . VSCode will display this command in the right-click menu * `FIX` [#1831] * `FIX` [#1838] +* `FIX` [#1841] [#1831]: https://github.com/sumneko/lua-language-server/issues/1831 [#1838]: https://github.com/sumneko/lua-language-server/issues/1838 +[#1841]: https://github.com/sumneko/lua-language-server/issues/1841 ## 3.6.7 `2023-1-20` diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua index 823029f01..6ce57d5c9 100644 --- a/script/vm/tracer.lua +++ b/script/vm/tracer.lua @@ -530,7 +530,7 @@ local lookIntoChild = util.switch() ---@param outNode? vm.node : call(function (tracer, action, topNode, outNode) for _, ret in ipairs(action) do - tracer:lookIntoChild(ret, topNode) + tracer:lookIntoChild(ret, topNode:copy()) end return topNode, outNode end) @@ -571,7 +571,7 @@ local lookIntoChild = util.switch() for i = 2, #action.args do tracer:lookIntoChild(action.args[i], topNode, topNode:copy()) end - topNode = tracer:lookIntoChild(action.args[1], topNode, topNode:copy()) + topNode = tracer:lookIntoChild(action.args[1], topNode:copy(), topNode:copy()) end tracer:lookIntoChild(action.node, topNode) tracer:lookIntoChild(action.args, topNode) diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 7882df691..8f3d6936c 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -1180,6 +1180,16 @@ local x - 类型 `nil` 无法匹配 `'A'`]]) end) +TEST [[ +---@param v integer +---@return boolean +local function is_string(v) + return type(v) == 'string' +end + +print(is_string(3)) +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'unused-function') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')