summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/vm/type.lua11
-rw-r--r--test/diagnostics/type-check.lua11
3 files changed, 19 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index d5f2eaeb..51ecae09 100644
--- a/changelog.md
+++ b/changelog.md
@@ -69,6 +69,7 @@
* `FIX` [#1317](https://github.com/sumneko/lua-language-server/issues/1317)
* `FIX` [#1320](https://github.com/sumneko/lua-language-server/issues/1320)
* `FIX` [#1330](https://github.com/sumneko/lua-language-server/issues/1330)
+* `FIX` [#1346](https://github.com/sumneko/lua-language-server/issues/1346)
## 3.4.2
`2022-7-6`
diff --git a/script/vm/type.lua b/script/vm/type.lua
index 5d42de6c..6f2d6f35 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -105,13 +105,16 @@ function vm.isSubType(uri, child, parent, mark)
child = global
elseif child.type == 'vm.node' then
if config.get(uri, 'Lua.type.weakUnionCheck') then
+ local hasKnownType
for n in child:eachObject() do
- if getNodeName(n)
- and vm.isSubType(uri, n, parent, mark) then
- return true
+ if getNodeName(n) then
+ hasKnownType = true
+ if vm.isSubType(uri, n, parent, mark) then
+ return true
+ end
end
end
- return false
+ return not hasKnownType
else
local weakNil = config.get(uri, 'Lua.type.weakNilCheck')
for n in child:eachObject() do
diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua
index b99e226c..c3bc3301 100644
--- a/test/diagnostics/type-check.lua
+++ b/test/diagnostics/type-check.lua
@@ -1,6 +1,7 @@
local config = require 'config'
config.add(nil, 'Lua.diagnostics.disable', 'unused-local')
+config.add(nil, 'Lua.diagnostics.disable', 'unused-function')
config.add(nil, 'Lua.diagnostics.disable', 'undefined-global')
TEST [[
@@ -727,6 +728,15 @@ TEST [[
---@type number
local x = G
]]
+
+TEST [[
+---@generic T
+---@param x T
+---@return T
+local function f(x)
+ return x
+end
+]]
config.set(nil, 'Lua.type.weakUnionCheck', false)
TEST [[
@@ -765,4 +775,5 @@ f(<!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')