From e8b46e34769bb1ad974f19ab214f943df8cce072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 13 Jan 2023 17:05:50 +0800 Subject: fix --- script/vm/compiler.lua | 2 +- script/vm/global.lua | 2 +- test/type_inference/init.lua | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 5a078e70..7a89cbf4 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1270,7 +1270,7 @@ local compilerSwitch = util.switch() ---@cast key string vm.compileByParentNode(source.node, key, function (src) vm.setNode(source, vm.compileNode(src)) - if src == source and source.value then + if src == source and source.value and source.value.type ~= 'nil' then vm.setNode(source, vm.compileNode(source.value)) end end) diff --git a/script/vm/global.lua b/script/vm/global.lua index 19474bb5..c1b5f320 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -552,7 +552,7 @@ function vm.compileByGlobal(source) if vm.bindDocs(source) then return true end - if source.value then + if source.value and source.value.type ~= 'nil' then vm.setNode(source, vm.compileNode(source.value)) return true end diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index ed29d3d1..9172ca92 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3407,12 +3407,12 @@ TEST '{ [string]: number, [true]: string, [1]: boolean, tag: integer }' [[ local ]] -TEST 'nil' [[ +TEST 'unknown' [[ local mt = {} mt. = nil ]] -TEST 'nil' [[ +TEST 'unknown' [[ mt = {} mt. = nil ]] @@ -4189,3 +4189,13 @@ X.Y = 1 print(X.) ]] + +TEST 'integer' [[ +local x = {} + +x.y = 1 +local y = x.y +x.y = nil + +print() +]] -- cgit v1.2.3