diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-02-13 15:43:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-02-13 15:43:52 +0800 |
commit | 48a608d423901c75138d51c9bcffbb0c03f4f92f (patch) | |
tree | 14034ac9ed1b9c9e228b64760d5836c5b2c34e1d | |
parent | 457931e51b1fec849635fd43355de1215e058228 (diff) | |
download | lua-language-server-48a608d423901c75138d51c9bcffbb0c03f4f92f.zip |
fix #1902
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/vm/tracer.lua | 3 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 10 |
3 files changed, 14 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 9de56cf6..eebfc461 100644 --- a/changelog.md +++ b/changelog.md @@ -6,11 +6,13 @@ * `FIX` [#1887] * `FIX` [#1889] * `FIX` [#1895] +* `FIX` [#1902] [#1886]: https://github.com/LuaLS/lua-language-server/issues/1886 [#1887]: https://github.com/LuaLS/lua-language-server/issues/1887 [#1889]: https://github.com/LuaLS/lua-language-server/issues/1889 [#1895]: https://github.com/LuaLS/lua-language-server/issues/1895 +[#1902]: https://github.com/LuaLS/lua-language-server/issues/1902 ## 3.6.10 `2023-2-7` diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua index b526d087..a8aa0c7c 100644 --- a/script/vm/tracer.lua +++ b/script/vm/tracer.lua @@ -641,7 +641,8 @@ local lookIntoChild = util.switch() and handler.args[1] and tracer.getMap[handler.args[1]] then -- if type(x) == 'string' then - tracer:lookIntoChild(handler, topNode:copy()) + tracer:lookIntoChild(handler, topNode) + topNode = topNode:copy() if action.op.type == '==' then topNode:narrow(tracer.uri, checker[1]) if outNode then diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 13df5a95..198ead64 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -1201,6 +1201,16 @@ local function some_fn(some_param) return end some_fn { { "test" } } -- <- diagnostic: "Cannot assign `table` to `string`." ]] +TEST [[ +---@param p integer|string +local function get_val(p) + local is_number = type(p) == 'number' + return is_number and p or p +end + +get_val('hi') +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'unused-function') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') |