Skip to content

Commit a92a800

Browse files
committed
fix #1346
1 parent 38ad313 commit a92a800

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
* `FIX` [#1317](https://github.com/sumneko/lua-language-server/issues/1317)
7070
* `FIX` [#1320](https://github.com/sumneko/lua-language-server/issues/1320)
7171
* `FIX` [#1330](https://github.com/sumneko/lua-language-server/issues/1330)
72+
* `FIX` [#1346](https://github.com/sumneko/lua-language-server/issues/1346)
7273

7374
## 3.4.2
7475
`2022-7-6`

script/vm/type.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,16 @@ function vm.isSubType(uri, child, parent, mark)
105105
child = global
106106
elseif child.type == 'vm.node' then
107107
if config.get(uri, 'Lua.type.weakUnionCheck') then
108+
local hasKnownType
108109
for n in child:eachObject() do
109-
if getNodeName(n)
110-
and vm.isSubType(uri, n, parent, mark) then
111-
return true
110+
if getNodeName(n) then
111+
hasKnownType = true
112+
if vm.isSubType(uri, n, parent, mark) then
113+
return true
114+
end
112115
end
113116
end
114-
return false
117+
return not hasKnownType
115118
else
116119
local weakNil = config.get(uri, 'Lua.type.weakNilCheck')
117120
for n in child:eachObject() do

test/diagnostics/type-check.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local config = require 'config'
22

33
config.add(nil, 'Lua.diagnostics.disable', 'unused-local')
4+
config.add(nil, 'Lua.diagnostics.disable', 'unused-function')
45
config.add(nil, 'Lua.diagnostics.disable', 'undefined-global')
56

67
TEST [[
@@ -727,6 +728,15 @@ TEST [[
727728
---@type number
728729
local x = G
729730
]]
731+
732+
TEST [[
733+
---@generic T
734+
---@param x T
735+
---@return T
736+
local function f(x)
737+
return x
738+
end
739+
]]
730740
config.set(nil, 'Lua.type.weakUnionCheck', false)
731741

732742
TEST [[
@@ -765,4 +775,5 @@ f(<!3!>)
765775
]]
766776

767777
config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
778+
config.remove(nil, 'Lua.diagnostics.disable', 'unused-function')
768779
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')

0 commit comments

Comments
 (0)