diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-16 03:56:56 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-16 03:56:56 +0800 |
commit | b96fcdde819031b20c49e2070a3aaf070fb74088 (patch) | |
tree | 7e214de44b1f11e1183257472277c3cba4b7a17b /script | |
parent | 6c5594a2026604d47d3c94ae07d0514b6616d63b (diff) | |
download | lua-language-server-b96fcdde819031b20c49e2070a3aaf070fb74088.zip |
#1058 fix runtime errors
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/compiler.lua | 8 | ||||
-rw-r--r-- | script/vm/global-manager.lua | 3 | ||||
-rw-r--r-- | script/vm/type.lua | 26 | ||||
-rw-r--r-- | script/vm/value.lua | 34 |
4 files changed, 54 insertions, 17 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e3c7e2b9..8126f393 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -748,10 +748,14 @@ local function compileLocalBase(source) hasMarkParam = true if source.parent.type == 'callargs' then -- obj:func(...) - vm.setNode(source, vm.compileNode(source.parent.parent.node.node)) + if source.parent.parent and source.parent.parent.node and source.parent.parent.node.node then + vm.setNode(source, vm.compileNode(source.parent.parent.node.node)) + end else -- function obj:func(...) - vm.setNode(source, vm.compileNode(source.parent.parent.parent.node)) + if source.parent.parent and source.parent.parent.parent and source.parent.parent.parent.node then + vm.setNode(source, vm.compileNode(source.parent.parent.parent.node)) + end end end local hasMarkValue diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index 1481f14e..f25bb5a0 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -121,6 +121,9 @@ local compilerGlobalSwitch = util.switch() : call(function (source) if source.node.special == 'rawset' or source.node.special == 'rawget' then + if not source.args then + return + end local g = source.args[1] local key = source.args[2] if g and key and g.special == '_G' then diff --git a/script/vm/type.lua b/script/vm/type.lua index 5c8a8088..fa02d19e 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -78,7 +78,9 @@ function vm.getTableValue(uri, tnode, knode) if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do if vm.isSubType(uri, vm.compileNode(field.name), knode) then - result:merge(vm.compileNode(field.extends)) + if field.extends then + result:merge(vm.compileNode(field.extends)) + end end end end @@ -88,16 +90,22 @@ function vm.getTableValue(uri, tnode, knode) if tn.type == 'table' then for _, field in ipairs(tn) do if field.type == 'tableindex' then - result:merge(vm.compileNode(field.value)) + if field.value then + result:merge(vm.compileNode(field.value)) + end end if field.type == 'tablefield' then if vm.isSubType(uri, knode, 'string') then - result:merge(vm.compileNode(field.value)) + if field.value then + result:merge(vm.compileNode(field.value)) + end end end if field.type == 'tableexp' then if vm.isSubType(uri, knode, 'integer') and field.tindex == 1 then - result:merge(vm.compileNode(field.value)) + if field.value then + result:merge(vm.compileNode(field.value)) + end end end end @@ -118,8 +126,10 @@ function vm.getTableKey(uri, tnode, vnode) for tn in tnode:eachObject() do if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do - if vm.isSubType(uri, vm.compileNode(field.extends), vnode) then - result:merge(vm.compileNode(field.name)) + if field.extends then + if vm.isSubType(uri, vm.compileNode(field.extends), vnode) then + result:merge(vm.compileNode(field.name)) + end end end end @@ -129,7 +139,9 @@ function vm.getTableKey(uri, tnode, vnode) if tn.type == 'table' then for _, field in ipairs(tn) do if field.type == 'tableindex' then - result:merge(vm.compileNode(field.index)) + if field.index then + result:merge(vm.compileNode(field.index)) + end end if field.type == 'tablefield' then result:merge(globalMgr.getGlobal('type', 'string')) diff --git a/script/vm/value.lua b/script/vm/value.lua index 10107212..a784be2a 100644 --- a/script/vm/value.lua +++ b/script/vm/value.lua @@ -2,9 +2,12 @@ local guide = require 'parser.guide' ---@class vm local vm = require 'vm.vm' ----@param source parser.object +---@param source parser.object? ---@return boolean|nil function vm.test(source) + if not source then + return nil + end local node = vm.compileNode(source) local hasTrue, hasFalse for n in node:eachObject() do @@ -87,8 +90,8 @@ local function getUnique(v) return false end ----@param a vm.node ----@param b vm.node +---@param a vm.object? +---@param b vm.object? ---@return boolean|nil function vm.equal(a, b) if not a or not b then @@ -116,9 +119,12 @@ function vm.equal(a, b) return true end ----@param v vm.node +---@param v vm.object? ---@return integer? function vm.getInteger(v) + if not v then + return nil + end local node = vm.compileNode(v) local result for n in node:eachObject() do @@ -144,9 +150,12 @@ function vm.getInteger(v) return result end ----@param v vm.node +---@param v vm.object? ---@return integer? function vm.getString(v) + if not v then + return nil + end local node = vm.compileNode(v) local result for n in node:eachObject() do @@ -164,9 +173,12 @@ function vm.getString(v) return result end ----@param v vm.node +---@param v vm.object? ---@return number? function vm.getNumber(v) + if not v then + return nil + end local node = vm.compileNode(v) local result for n in node:eachObject() do @@ -185,9 +197,12 @@ function vm.getNumber(v) return result end ----@param v vm.node +---@param v vm.object ---@return boolean|nil function vm.getBoolean(v) + if not v then + return nil + end local node = vm.compileNode(v) local result for n in node:eachObject() do @@ -205,9 +220,12 @@ function vm.getBoolean(v) return result end ----@param v vm.node +---@param v vm.object ---@return table<any, boolean>? function vm.getLiterals(v) + if not v then + return nil + end local map local node = vm.compileNode(v) for n in node:eachObject() do |