diff options
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/vm/compiler.lua | 57 | ||||
-rw-r--r-- | script/vm/global-manager.lua | 6 | ||||
-rw-r--r-- | script/vm/sign.lua | 2 | ||||
-rw-r--r-- | script/vm/type.lua | 6 |
5 files changed, 44 insertions, 30 deletions
diff --git a/changelog.md b/changelog.md index 798514ac..f2df0b94 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 3.2.2 +* `FIX` runtime errors reported by telemetry, see [#1091](https://github.com/sumneko/lua-language-server/issues/1091) + ## 3.2.1 `2022-4-25` * `FIX` broken in VSCode diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index db54b6c8..4d26ce8c 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -647,7 +647,7 @@ local function selectNode(source, list, index) if exp.type == 'call' then result = getReturn(exp.node, index, exp.args) if not result then - vm.setNode(source, globalMgr.getGlobal('type', 'unknown')) + vm.setNode(source, globalMgr.declareGlobal('type', 'unknown')) return vm.getNode(source) end else @@ -673,7 +673,7 @@ local function selectNode(source, list, index) end end if not hasKnownType then - rtnNode:merge(globalMgr.getGlobal('type', 'unknown')) + rtnNode:merge(globalMgr.declareGlobal('type', 'unknown')) end vm.setNode(source, rtnNode) return rtnNode @@ -877,7 +877,7 @@ local function compileLocal(source) end end if not hasDocArg then - vm.setNode(source, globalMgr.getGlobal('type', 'any')) + vm.setNode(source, globalMgr.declareGlobal('type', 'any')) end end -- for x in ... do @@ -1252,7 +1252,7 @@ local compilerSwitch = util.switch() : case 'loop' : call(function (source) if source.loc then - vm.setNode(source.loc, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source.loc, globalMgr.declareGlobal('type', 'integer')) end end) : case 'doc.type' @@ -1278,6 +1278,9 @@ local compilerSwitch = util.switch() : call(function (source) local uri = guide.getUri(source) vm.setNode(source, source) + if not source.node[1] then + return + end local global = globalMgr.getGlobal('type', source.node[1]) if not global then return @@ -1377,7 +1380,7 @@ local compilerSwitch = util.switch() if source.extends then vm.setNode(source, vm.compileNode(source.extends)) else - vm.setNode(source, globalMgr.getGlobal('type', 'any')) + vm.setNode(source, globalMgr.declareGlobal('type', 'any')) end if source.optional then vm.getNode(source):addOptional() @@ -1392,10 +1395,13 @@ local compilerSwitch = util.switch() if bindAs(source) then return end + if not source[1] then + return + end if source.op.type == 'not' then local result = vm.test(source[1]) if result == nil then - vm.setNode(source, globalMgr.getGlobal('type', 'boolean')) + vm.setNode(source, globalMgr.declareGlobal('type', 'boolean')) return else vm.setNode(source, { @@ -1409,13 +1415,13 @@ local compilerSwitch = util.switch() end end if source.op.type == '#' then - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return end if source.op.type == '-' then local v = vm.getNumber(source[1]) if v == nil then - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return else vm.setNode(source, { @@ -1431,7 +1437,7 @@ local compilerSwitch = util.switch() if source.op.type == '~' then local v = vm.getInteger(source[1]) if v == nil then - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return else vm.setNode(source, { @@ -1450,6 +1456,9 @@ local compilerSwitch = util.switch() if bindAs(source) then return end + if not source[1] or not source[2] then + return + end if source.op.type == 'and' then local node1 = vm.compileNode(source[1]) local node2 = vm.compileNode(source[2]) @@ -1479,7 +1488,7 @@ local compilerSwitch = util.switch() if source.op.type == '==' then local result = vm.equal(source[1], source[2]) if result == nil then - vm.setNode(source, globalMgr.getGlobal('type', 'boolean')) + vm.setNode(source, globalMgr.declareGlobal('type', 'boolean')) return else vm.setNode(source, { @@ -1495,7 +1504,7 @@ local compilerSwitch = util.switch() if source.op.type == '~=' then local result = vm.equal(source[1], source[2]) if result == nil then - vm.setNode(source, globalMgr.getGlobal('type', 'boolean')) + vm.setNode(source, globalMgr.declareGlobal('type', 'boolean')) return else vm.setNode(source, { @@ -1521,7 +1530,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return end end @@ -1538,7 +1547,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return end end @@ -1555,7 +1564,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return end end @@ -1572,7 +1581,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return end end @@ -1589,7 +1598,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'integer')) + vm.setNode(source, globalMgr.declareGlobal('type', 'integer')) return end end @@ -1607,7 +1616,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1625,7 +1634,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1643,7 +1652,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1660,7 +1669,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1678,7 +1687,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1695,7 +1704,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1713,7 +1722,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'number')) + vm.setNode(source, globalMgr.declareGlobal('type', 'number')) return end end @@ -1750,7 +1759,7 @@ local compilerSwitch = util.switch() }) return else - vm.setNode(source, globalMgr.getGlobal('type', 'string')) + vm.setNode(source, globalMgr.declareGlobal('type', 'string')) return end end diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index 07c8950e..5891ba41 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -209,11 +209,13 @@ local compilerGlobalSwitch = util.switch() ---@param cate vm.global.cate ---@param name string ----@param uri uri +---@param uri? uri ---@return vm.global function m.declareGlobal(cate, name, uri) local key = cate .. '|' .. name - m.globalSubs[uri][key] = true + if uri then + m.globalSubs[uri][key] = true + end if not m.globals[key] then m.globals[key] = globalBuilder(name, cate) end diff --git a/script/vm/sign.lua b/script/vm/sign.lua index 795916fa..53435129 100644 --- a/script/vm/sign.lua +++ b/script/vm/sign.lua @@ -58,7 +58,7 @@ function mt:resolve(uri, args, removeGeneric) end if n.type == 'global' and n.cate == 'type' then -- ---@field [integer]: number -> T[] - vm.getClassFields(uri, n, globalMgr.getGlobal('type', 'integer'), false, function (field) + vm.getClassFields(uri, n, globalMgr.declareGlobal('type', 'integer'), false, function (field) resolve(object.node, vm.compileNode(field.extends)) end) end diff --git a/script/vm/type.lua b/script/vm/type.lua index fa02d19e..691490ec 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -134,7 +134,7 @@ function vm.getTableKey(uri, tnode, vnode) end end if tn.type == 'doc.type.array' then - result:merge(globalMgr.getGlobal('type', 'integer')) + result:merge(globalMgr.declareGlobal('type', 'integer')) end if tn.type == 'table' then for _, field in ipairs(tn) do @@ -144,10 +144,10 @@ function vm.getTableKey(uri, tnode, vnode) end end if field.type == 'tablefield' then - result:merge(globalMgr.getGlobal('type', 'string')) + result:merge(globalMgr.declareGlobal('type', 'string')) end if field.type == 'tableexp' then - result:merge(globalMgr.getGlobal('type', 'integer')) + result:merge(globalMgr.declareGlobal('type', 'integer')) end end end |