From 60189b2603798bba46e0c0aefdbad575efebfcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 5 Jul 2022 14:50:16 +0800 Subject: fix #1267 --- script/vm/compiler.lua | 3 ++- script/vm/node.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'script') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e361d706..1936fc75 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1309,7 +1309,8 @@ local compilerSwitch = util.switch() end if src.value then if src.value.type == 'table' then - vm.setNode(src, vm.createNode(src.value), true) + vm.setNode(src, vm.createNode(src.value)) + vm.setNode(src, node:copy():asTable()) else vm.setNode(src, vm.compileNode(src.value), true) end diff --git a/script/vm/node.lua b/script/vm/node.lua index 45e5e6c4..f0d0b0ba 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -227,6 +227,7 @@ function mt:remove(name) or (c.type == 'doc.type.boolean' and name == 'false' and c[1] == false) or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.sign' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then table.remove(self, index) self[c] = nil @@ -247,6 +248,7 @@ function mt:narrow(name) or (c.type == 'doc.type.boolean' and name == 'boolean') or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.sign' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then goto CONTINUE end @@ -328,6 +330,31 @@ function mt:hasName(name) return false end +---@return vm.node +function mt:asTable() + self.optional = nil + for index = #self, 1, -1 do + local c = self[index] + if c.type == 'table' + or c.type == 'doc.type.table' + or c.type == 'doc.type.array' + or c.type == 'doc.type.sign' then + goto CONTINUE + end + if c.type == 'global' and c.cate == 'type' then + ---@cast c vm.global + if c.name == 'table' + or not guide.isBasicType(c.name) then + goto CONTINUE + end + end + table.remove(self, index) + self[c] = nil + ::CONTINUE:: + end + return self +end + ---@return fun():vm.node.object function mt:eachObject() local i = 0 -- cgit v1.2.3