diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-01-11 22:03:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-01-11 22:03:43 +0800 |
commit | 390474caca77ea5e745f3a3ae2ca7168e7165573 (patch) | |
tree | 97bdcf92bf6ec60d802f795f47e59bb8e33f3c61 /script/vm/compiler.lua | |
parent | d74c85c8517b9f3b7591cc337fa387f2805ebb40 (diff) | |
download | lua-language-server-390474caca77ea5e745f3a3ae2ca7168e7165573.zip |
stash
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r-- | script/vm/compiler.lua | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index b3052c60..dc81e836 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -67,6 +67,9 @@ local function searchFieldByLocalID(source, key, pushResult) if key then if source.type == 'variable' then ---@cast source vm.variable + if type(key) ~= 'string' then + return + end fields = source:getSets(key) else ---@cast source parser.object @@ -728,13 +731,13 @@ function vm.selectNode(list, index) local result if exp.type == 'call' then result = getReturn(exp.node, index, exp.args) - if not result:isTyped() then + if result:isEmpty() then result:merge(vm.declareGlobal('type', 'unknown')) end else ---@type vm.node result = vm.compileNode(exp) - if not result:isTyped() then + if result:isEmpty() then result:merge(vm.declareGlobal('type', 'unknown')) end end @@ -1233,6 +1236,9 @@ local compilerSwitch = util.switch() : case 'getmethod' : case 'getindex' : call(function (source) + if bindDocs(source) then + return + end if guide.isGet(source) and bindAs(source) then return end @@ -1257,18 +1263,28 @@ local compilerSwitch = util.switch() ---@cast k vm.global vm.compileByParentNode(source.node, k, function (src) vm.setNode(source, vm.compileNode(src)) - if src.value then - vm.setNode(source, vm.compileNode(src.value)) - end end) end end else if guide.isGet(source) then - local node = vm.traceNode(source) - if node then - vm.setNode(source, node) - return + --local node = vm.traceNode(source) + --if node then + -- vm.setNode(source, node) + --end + ---@cast key string + vm.compileByParentNode(source.node, key, function (src) + vm.setNode(source, vm.compileNode(src)) + end) + else + local hasDefinedField + ---@cast key string + vm.compileByParentNode(source.node, key, function (src) + hasDefinedField = true + vm.setNode(source, vm.compileNode(src)) + end) + if not hasDefinedField and source.value then + vm.setNode(source, vm.compileNode(source.value)) end end end @@ -1767,26 +1783,6 @@ local compilerSwitch = util.switch() vm.setNode(variable, vm.compileNode(variable.base)) return end - local parentVariable = variable:getParent() - local fieldName = variable:getFieldName() - if not parentVariable or not fieldName then - return - end - vm.compileByParentNode(parentVariable, fieldName, function (src) - if src.value then - if bindDocs(src) then - vm.setNode(variable, vm.compileNode(src)) - elseif src.value.type ~= 'nil' then - vm.setNode(variable, vm.compileNode(src.value)) - local node = vm.getNode(src) - if node then - vm.setNode(variable, node) - end - end - else - vm.setNode(variable, vm.compileNode(src)) - end - end) end) ---@param source parser.object |