diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-02-15 16:11:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-02-15 16:11:40 +0800 |
commit | 0f865006938ce7d8ada60c48ae92b588e91142b4 (patch) | |
tree | 609f9121e0d5a0da76ac2135d9e52ddaa4dcbfdc /script | |
parent | c28f8c8635105010e54033b2f47065c291590264 (diff) | |
download | lua-language-server-0f865006938ce7d8ada60c48ae92b588e91142b4.zip |
fix runtime error
#1911
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/infer.lua | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 3045bbdb..94fdfd88 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -243,6 +243,16 @@ local viewNodeSwitch;viewNodeSwitch = util.switch() ---@class vm.node ---@field lastInfer? vm.infer +---@param node? vm.node +---@return vm.infer +local function createInfer(node) + local infer = setmetatable({ + node = node, + _drop = {}, + }, mt) + return infer +end + ---@param source vm.node.object | vm.node ---@return vm.infer function vm.getInfer(source) @@ -258,10 +268,7 @@ function vm.getInfer(source) if node.lastInfer then return node.lastInfer end - local infer = setmetatable({ - node = node, - _drop = {}, - }, mt) + local infer = createInfer(node) node.lastInfer = infer return infer @@ -311,9 +318,7 @@ function mt:_eraseAlias(uri) if set.type == 'doc.alias' then if expandAlias then self._drop[n.name] = true - local newInfer = setmetatable({ - _drop = {}, - }, mt) + local newInfer = createInfer() for _, ext in ipairs(set.extends.types) do viewNodeSwitch(ext.type, ext, newInfer, uri) end @@ -322,7 +327,7 @@ function mt:_eraseAlias(uri) end else for _, ext in ipairs(set.extends.types) do - local view = viewNodeSwitch(ext.type, ext, {}, uri) + local view = viewNodeSwitch(ext.type, ext, createInfer(), uri) if view and view ~= n.name then self._drop[view] = true end @@ -546,9 +551,7 @@ end ---@param uri uri ---@return string? function vm.viewObject(source, uri) - local infer = setmetatable({ - _drop = {}, - }, mt) + local infer = createInfer() return viewNodeSwitch(source.type, source, infer, uri) end |