From 0f865006938ce7d8ada60c48ae92b588e91142b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Feb 2023 16:11:40 +0800 Subject: fix runtime error #1911 --- script/vm/infer.lua | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'script/vm/infer.lua') 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 -- cgit v1.2.3