From 36ed61dc66433c13c99feb9d3650b31792454615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 2 Feb 2023 15:45:07 +0800 Subject: [PATCH] fix #1871 --- changelog.md | 2 ++ script/vm/compiler.lua | 10 +++++----- test/diagnostics/type-check.lua | 11 +++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index a25bf55b4..1104e87ad 100644 --- a/changelog.md +++ b/changelog.md @@ -4,10 +4,12 @@ * `FIX` [#1864] * `FIX` [#1868] * `FIX` [#1869] +* `FIX` [#1871] [#1864]: https://github.com/sumneko/lua-language-server/issues/1864 [#1868]: https://github.com/sumneko/lua-language-server/issues/1868 [#1869]: https://github.com/sumneko/lua-language-server/issues/1869 +[#1871]: https://github.com/sumneko/lua-language-server/issues/1871 ## 3.6.8 `2023-1-31` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 4f97b0e06..6e76f470c 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -192,11 +192,11 @@ local searchFieldSwitch = util.switch() or not math.tointeger(key) then return end - pushResult(source.node) + pushResult(source.node, true) end if type(key) == 'table' then if vm.isSubType(suri, key, 'integer') then - pushResult(source.node) + pushResult(source.node, true) end end end) @@ -217,21 +217,21 @@ local searchFieldSwitch = util.switch() or (fn.name == 'number' and type(key) == 'number') or (fn.name == 'integer' and math.tointeger(key)) or (fn.name == 'string' and type(key) == 'string') then - pushResult(field) + pushResult(field, true) end elseif fn.type == 'doc.type.string' or fn.type == 'doc.type.integer' or fn.type == 'doc.type.boolean' then if key == vm.ANY or fn[1] == key then - pushResult(field) + pushResult(field, true) end end end end if fieldKey.type == 'doc.field.name' then if key == vm.ANY or fieldKey[1] == key then - pushResult(field) + pushResult(field, true) end end end diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 8f3d6936c..13df5a957 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -1190,6 +1190,17 @@ end print(is_string(3)) ]] +TEST [[ +---@class SomeClass +---@field [1] string +-- ... + +---@param some_param SomeClass|SomeClass[] +local function some_fn(some_param) return end + +some_fn { { "test" } } -- <- diagnostic: "Cannot assign `table` to `string`." +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'unused-function') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')