diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-15 15:25:38 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-15 15:25:38 +0800 |
commit | 98fe538e564bac10e5df65c31e20b8dc3317e87d (patch) | |
tree | 08fa752ef06ed64c7bfe7358115e1bc6fb6e4b85 | |
parent | ed2fd90278a6e913186ddfbbb8939733c640102b (diff) | |
download | lua-language-server-98fe538e564bac10e5df65c31e20b8dc3317e87d.zip |
fix
-rw-r--r-- | script/vm/runner.lua | 9 | ||||
-rw-r--r-- | test/type_inference/init.lua | 36 |
2 files changed, 43 insertions, 2 deletions
diff --git a/script/vm/runner.lua b/script/vm/runner.lua index a9c38a87..e7851b49 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -114,6 +114,9 @@ end ---@param outNode? vm.node ---@return vm.node function mt:_lookInto(action, topNode, outNode) + if not action then + return topNode, outNode + end local set local value = vm.getObjectValue(action) if value then @@ -128,7 +131,9 @@ function mt:_lookInto(action, topNode, outNode) self:_launchBlock(action, topNode:copy()) elseif action.type == 'while' then local blockNode, mainNode = self:_lookInto(action.filter, topNode:copy(), topNode:copy()) - self:_fastWard(action.filter.finish, blockNode) + if action.filter then + self:_fastWard(action.filter.finish, blockNode) + end self:_launchBlock(action, blockNode:copy()) topNode = mainNode elseif action.type == 'if' then @@ -201,7 +206,7 @@ function mt:_lookInto(action, topNode, outNode) end end if loc then - self:_fastWard(loc.finish, topNode) + self:_fastWard(loc.finish, topNode:copy()) if guide.isLiteral(checker) then local checkerNode = vm.compileNode(checker) if action.op.type == '==' then diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index ecc22a3f..0a19082a 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -2512,3 +2512,39 @@ TEST 'fun(x: fun(x: unknown))' [[ ---@type xxx local <?t?> ]] + +TEST 'table' [[ +---@type table|nil +local t + +while t do + print(<?t?>) +end +]] + +TEST 'table|nil' [[ +---@type table|nil +local t + +while <?t?> do + print(t) +end +]] + +TEST 'table' [[ +---@type table|nil +local t + +while t ~= nil do + print(<?t?>) +end +]] + +TEST 'table|nil' [[ +---@type table|nil +local t + +while <?t?> ~= nil do + print(t) +end +]] |