diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-09-15 15:57:56 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-09-15 15:57:56 +0800 |
commit | e2df6d85fb15c50b96811d1923079d003e7f52d4 (patch) | |
tree | a770acc0419a2ed37632c8a452f8b7c57ab292dc /script/vm/compiler.lua | |
parent | 0f96c63cafc98b6574c8ae5d31c59bcca24dc50a (diff) | |
download | lua-language-server-e2df6d85fb15c50b96811d1923079d003e7f52d4.zip |
fix #1467
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r-- | script/vm/compiler.lua | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index b0694a4b..e59d7a6f 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -942,33 +942,41 @@ end ---@field _iterVars? table<parser.object, vm.node> ---@param source parser.object -local function compileForVars(source) - if source._iterator then - return - end +---@param target parser.object +local function compileForVars(source, target) if not source.exps then return end - -- for k, v in pairs(t) do - --> for k, v in iterator, status, initValue do - --> local k, v = iterator(status, initValue) - source._iterator = { - type = 'dummyfunc', - parent = source, - } - source._iterArgs = {{},{}} - source._iterVars = {} + -- for k, v in pairs(t) do + --> for k, v in iterator, status, initValue do + --> local k, v = iterator(status, initValue) + if not source._iterator then + source._iterator = { + type = 'dummyfunc', + parent = source, + } + source._iterArgs = {{},{}} + source._iterVars = {} + end -- iterator - selectNode(source._iterator, source.exps, 1) + if not vm.getNode(source._iterator) then + selectNode(source._iterator, source.exps, 1) + end -- status - selectNode(source._iterArgs[1], source.exps, 2) + if not vm.getNode(source._iterArgs[1]) then + selectNode(source._iterArgs[1], source.exps, 2) + end -- initValue - selectNode(source._iterArgs[2], source.exps, 3) + if not vm.getNode(source._iterArgs[2]) then + selectNode(source._iterArgs[2], source.exps, 3) + end if source.keys then for i, loc in ipairs(source.keys) do - local node = getReturn(source._iterator, i, source._iterArgs) - node:removeOptional() - source._iterVars[loc] = node + if loc == target then + local node = getReturn(source._iterator, i, source._iterArgs) + node:removeOptional() + vm.setNode(loc, node) + end end end end @@ -1053,11 +1061,7 @@ local function compileLocal(source) end -- for x in ... do if source.parent.type == 'in' then - compileForVars(source.parent) - local keyNode = source.parent._iterVars and source.parent._iterVars[source] - if keyNode then - vm.setNode(source, keyNode) - end + compileForVars(source.parent, source) end -- for x = ... do |