diff options
-rw-r--r-- | script/vm/compiler.lua | 11 | ||||
-rw-r--r-- | script/vm/global.lua | 9 | ||||
-rw-r--r-- | script/vm/tracer.lua | 5 | ||||
-rw-r--r-- | test/definition/bug.lua | 7 | ||||
-rw-r--r-- | test/signature/init.lua | 30 | ||||
-rw-r--r-- | test/type_inference/init.lua | 59 |
6 files changed, 64 insertions, 57 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index a36904f8..663d7446 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1303,16 +1303,13 @@ local compilerSwitch = util.switch() end) : case 'setglobal' : call(function (source) + if bindDocs(source) then + return + end if source.node[1] ~= '_ENV' then return end - local key = guide.getKeyName(source) - vm.compileByParentNode(source.node, key, function (src) - if src.type == 'doc.type.field' - or src.type == 'doc.field' then - vm.setNode(source, vm.compileNode(src)) - end - end) + vm.setNode(source, vm.compileNode(source.value)) end) : case 'getglobal' : call(function (source) diff --git a/script/vm/global.lua b/script/vm/global.lua index 5f32cd87..f9090893 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -521,10 +521,15 @@ function vm.compileByGlobal(source) if global.cate == 'variable' then vm.setNode(source, global) if guide.isAssign(source) then - vm.setNode(source, vm.compileNode(source.value)) + if source.value then + vm.setNode(source, vm.compileNode(source.value)) + end return end - vm.traceNode(source) + local node = vm.traceNode(source) + if node then + vm.setNode(source, node, true) + end return end local globalBase = vm.getGlobalBase(source) diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua index 025a6ae1..d4b9e5be 100644 --- a/script/vm/tracer.lua +++ b/script/vm/tracer.lua @@ -214,6 +214,7 @@ end local lookIntoChild = util.switch() : case 'getlocal' + : case 'getglobal' ---@param tracer vm.tracer ---@param action parser.object ---@param topNode vm.node @@ -466,7 +467,7 @@ local lookIntoChild = util.switch() and call.args then local getVar = call.args[1] if getVar - and tracer.assignMap[getVar] then + and tracer.getMap[getVar] then for _, ref in ipairs(action.ref) do tracer:collectCare(ref) end @@ -694,7 +695,7 @@ end ---@param source parser.object function mt:calcNode(source) if self.getMap[source] then - local lastAssign = self:getLastAssign(0, source.start) + local lastAssign = self:getLastAssign(0, source.finish) if not lastAssign then lastAssign = source.node end diff --git a/test/definition/bug.lua b/test/definition/bug.lua index b564f764..2e2a5972 100644 --- a/test/definition/bug.lua +++ b/test/definition/bug.lua @@ -48,6 +48,13 @@ obj[#<?obj?>+1] = {} TEST [[ self = { + <!results!> = {} +} +self[self.<?results?>] = lbl +]] + +TEST [[ +self = { results = { <!labels!> = {}, } diff --git a/test/signature/init.lua b/test/signature/init.lua index 17c5cecb..147f93e1 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -235,11 +235,8 @@ end)(<??>) {'function (<!a: any!>, b: any)'} TEST [[ -function X() end - ----@param a number -function X(a) end - +---@overload fun() +---@overload fun(a:number) ---@param a number ---@param b number function X(a, b) end @@ -252,12 +249,9 @@ X(<??>) 'function X(<!a: number!>, b: number)', } -TEST [[ -function X() end - ----@param a number -function X(a) end - +TEST [[\ +---@overload fun() +---@overload fun(a:number) ---@param a number ---@param b number function X(a, b) end @@ -270,11 +264,8 @@ X(<?1?>) } TEST [[ -function X() end - ----@param a number -function X(a) end - +---@overload fun() +---@overload fun(a:number) ---@param a number ---@param b number function X(a, b) end @@ -286,11 +277,8 @@ X(1, <??>) } TEST [[ -function X() end - ----@param a number -function X(a) end - +---@overload fun() +---@overload fun(a:number) ---@param a number ---@param b number function X(a, b) end diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 0b69a34c..db1d306e 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -2893,10 +2893,7 @@ local <?x?> = echo(b) ]] TEST 'boolean' [[ ----@return boolean -function f() -end - +---@overload fun():boolean ---@param x integer ---@return number function f(x) @@ -2906,10 +2903,7 @@ local <?x?> = f() ]] TEST 'number' [[ ----@return boolean -function f() -end - +---@overload fun():boolean ---@param x integer ---@return number function f(x) @@ -2919,10 +2913,7 @@ local <?x?> = f(1) ]] TEST 'boolean' [[ ----@return boolean -function f() -end - +---@overload fun():boolean ---@param x integer ---@return number function f(x) @@ -2936,10 +2927,7 @@ local <?x?> = f(r0()) ]] TEST 'number' [[ ----@return boolean -function f() -end - +---@overload fun():boolean ---@param x integer ---@return number function f(x) @@ -2953,10 +2941,7 @@ local <?x?> = f(r1()) ]] TEST 'boolean' [[ ----@return boolean -function f() -end - +---@overload fun():boolean ---@param x integer ---@return number function f(x) @@ -2969,10 +2954,7 @@ local <?x?> = f(r0()) ]] TEST 'number' [[ ----@return boolean -function f() -end - +---@overload fun():boolean ---@param x integer ---@return number function f(x) @@ -3430,7 +3412,7 @@ local mt = {} mt.<?x?> = nil ]] -TEST 'unknown' [[ +TEST 'nil' [[ mt = {} mt.<?x?> = nil ]] @@ -4148,3 +4130,30 @@ for _, <?x?> in ipairs(xs) do x = f(x) end ]] + +TEST 'number' [[ +---@type number? +X = Y + +if X then + print(<?X?>) +end +]] + +TEST 'number' [[ +---@type number|boolean +X = Y + +if type(X) == 'number' then + print(<?X?>) +end +]] + +TEST 'boolean' [[ +---@type number|boolean +X = Y + +if type(X) ~= 'number' then + print(<?X?>) +end +]] |