Skip to content

Commit e2df6d8

Browse files
committed
fix #1467
1 parent 0f96c63 commit e2df6d8

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# changelog
22

33
## 3.6.0
4+
* `FIX` [#1467](https://github.com/sumneko/lua-language-server/issues/1467)
45
* `FIX` [#1506](https://github.com/sumneko/lua-language-server/issues/1506)
56
* `FIX` [#1537](https://github.com/sumneko/lua-language-server/issues/1537)
67

script/vm/compiler.lua

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -942,33 +942,41 @@ end
942942
---@field _iterVars? table<parser.object, vm.node>
943943

944944
---@param source parser.object
945-
local function compileForVars(source)
946-
if source._iterator then
947-
return
948-
end
945+
---@param target parser.object
946+
local function compileForVars(source, target)
949947
if not source.exps then
950948
return
951949
end
952-
-- for k, v in pairs(t) do
953-
--> for k, v in iterator, status, initValue do
954-
--> local k, v = iterator(status, initValue)
955-
source._iterator = {
956-
type = 'dummyfunc',
957-
parent = source,
958-
}
959-
source._iterArgs = {{},{}}
960-
source._iterVars = {}
950+
-- for k, v in pairs(t) do
951+
--> for k, v in iterator, status, initValue do
952+
--> local k, v = iterator(status, initValue)
953+
if not source._iterator then
954+
source._iterator = {
955+
type = 'dummyfunc',
956+
parent = source,
957+
}
958+
source._iterArgs = {{},{}}
959+
source._iterVars = {}
960+
end
961961
-- iterator
962-
selectNode(source._iterator, source.exps, 1)
962+
if not vm.getNode(source._iterator) then
963+
selectNode(source._iterator, source.exps, 1)
964+
end
963965
-- status
964-
selectNode(source._iterArgs[1], source.exps, 2)
966+
if not vm.getNode(source._iterArgs[1]) then
967+
selectNode(source._iterArgs[1], source.exps, 2)
968+
end
965969
-- initValue
966-
selectNode(source._iterArgs[2], source.exps, 3)
970+
if not vm.getNode(source._iterArgs[2]) then
971+
selectNode(source._iterArgs[2], source.exps, 3)
972+
end
967973
if source.keys then
968974
for i, loc in ipairs(source.keys) do
969-
local node = getReturn(source._iterator, i, source._iterArgs)
970-
node:removeOptional()
971-
source._iterVars[loc] = node
975+
if loc == target then
976+
local node = getReturn(source._iterator, i, source._iterArgs)
977+
node:removeOptional()
978+
vm.setNode(loc, node)
979+
end
972980
end
973981
end
974982
end
@@ -1053,11 +1061,7 @@ local function compileLocal(source)
10531061
end
10541062
-- for x in ... do
10551063
if source.parent.type == 'in' then
1056-
compileForVars(source.parent)
1057-
local keyNode = source.parent._iterVars and source.parent._iterVars[source]
1058-
if keyNode then
1059-
vm.setNode(source, keyNode)
1060-
end
1064+
compileForVars(source.parent, source)
10611065
end
10621066

10631067
-- for x = ... do

0 commit comments

Comments
 (0)