Skip to content

Commit 05a098f

Browse files
committed
fix #1363 don't lookup globals in blocks
1 parent 6570692 commit 05a098f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* `CHG` improve supports for multi-workspace
66
* `FIX` [#1354](https://github.com/sumneko/lua-language-server/issues/1354)
77
* `FIX` [#1355](https://github.com/sumneko/lua-language-server/issues/1355)
8+
* `FIX` [#1363](https://github.com/sumneko/lua-language-server/issues/1363)
89
* `FIX` [#1368](https://github.com/sumneko/lua-language-server/issues/1368)
910

1011
## 3.5.0

script/core/diagnostics/unreachable-code.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ return function (uri, callback)
5050
---@async
5151
guide.eachSourceTypes(state.ast, {'main', 'function'}, function (source)
5252
await.delay()
53-
if not source.returns then
54-
return
55-
end
5653
for i, action in ipairs(source) do
5754
if guide.isBlockType(action)
5855
and hasReturn(action) then

script/vm/compiler.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ local function compileByGlobal(source)
17361736
if global.cate == 'variable' then
17371737
local hasMarkDoc
17381738
for _, set in ipairs(global:getSets(uri)) do
1739-
if set.bindDocs then
1739+
if set.bindDocs and set.parent.type == 'main' then
17401740
if bindDocs(set) then
17411741
globalNode:merge(vm.compileNode(set))
17421742
hasMarkDoc = true
@@ -1751,7 +1751,7 @@ local function compileByGlobal(source)
17511751
vm.setNode(set, globalNode, true)
17521752
end
17531753
for _, set in ipairs(global:getSets(uri)) do
1754-
if set.value and set.value.type ~= 'nil' then
1754+
if set.value and set.value.type ~= 'nil' and set.parent.type == 'main' then
17551755
if not hasMarkDoc or guide.isLiteral(set.value) then
17561756
globalNode:merge(vm.compileNode(set.value))
17571757
end

test/diagnostics/common.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,28 @@ function X()
19871987
end
19881988
]]
19891989

1990+
TEST [[
1991+
while true do
1992+
end
1993+
1994+
<!print(1)!>
1995+
]]
1996+
1997+
TEST [[
1998+
while true do
1999+
end
2000+
2001+
<!print(1)!>
2002+
]]
2003+
2004+
TEST [[
2005+
while X do
2006+
X = 1
2007+
end
2008+
2009+
print(1)
2010+
]]
2011+
19902012
TEST [[
19912013
---@diagnostic disable: undefined-global
19922014

0 commit comments

Comments
 (0)