diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-08 14:35:56 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-08 14:35:56 +0800 |
commit | 67a341f3fa26e5a3140cde3420ef2269a84d478f (patch) | |
tree | 8c747faa574055b7dfe2a22ef3a8176100b90980 /script/vm/compiler.lua | |
parent | 0b898555f495b80f278fec01d2f3e6ec83b4952c (diff) | |
download | lua-language-server-67a341f3fa26e5a3140cde3420ef2269a84d478f.zip |
cleanup
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r-- | script/vm/compiler.lua | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 43c7be1e..a87f2eba 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -443,6 +443,9 @@ function m.compileByParentNode(source, key, pushResult) end local function selectNode(source, list, index) + if not list then + return nil + end local exp if list[index] then exp = list[index] @@ -644,17 +647,6 @@ local compilerSwitch = util.switch() if source.bindDocs then hasMarkDoc = bindDocs(source) end - if source.ref and not hasMarkDoc then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - if ref.value and ref.value.type == 'table' then - nodeMgr.setNode(source, ref.value) - else - nodeMgr.setNode(source, m.compileNode(ref.value)) - end - end - end - end local hasMarkParam if source.dummy and not hasMarkDoc then hasMarkParam = true @@ -669,6 +661,19 @@ local compilerSwitch = util.switch() end end end + if not source.value + and source.ref + and not hasMarkDoc then + for _, ref in ipairs(source.ref) do + if ref.type == 'setlocal' then + if ref.value and ref.value.type == 'table' then + nodeMgr.setNode(source, ref.value) + else + nodeMgr.setNode(source, m.compileNode(ref.value)) + end + end + end + end -- function x.y(self, ...) --> function x:y(...) if source[1] == 'self' and not hasMarkDoc @@ -707,11 +712,25 @@ local compilerSwitch = util.switch() if source.parent.type == 'loop' then nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer')) end + + -- avoid self reference + -- `local x; x = x` + -- the third `x` is unknown here + -- x[1] -> value of x[2] -> x[3] -> x[1](locked!) + if source.ref then + local myNode = nodeMgr.getNode(source) + for _, ref in ipairs(source.ref) do + if ref.type == 'setlocal' + or ref.type == 'getlocal' then + nodeMgr.setNode(ref, myNode, true) + end + end + end end) : case 'setlocal' : case 'getlocal' : call(function (source) - nodeMgr.setNode(source, m.compileNode(source.node)) + nodeMgr.setNode(source, m.compileNode(source.node), true) end) : case 'setfield' : case 'setmethod' |