Skip to content

Commit

Permalink
fix #1889
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Feb 10, 2023
1 parent 5e112de commit 4b0d634
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* `CHG` completion: don't show loading process
* `FIX` [#1886]
* `FIX` [#1895]
* `FIX` [#1889]

[#1886]: https://github.com/LuaLS/lua-language-server/issues/1886
[#1895]: https://github.com/LuaLS/lua-language-server/issues/1895
[#1889]: https://github.com/LuaLS/lua-language-server/issues/1889

## 3.6.10
`2023-2-7`
Expand Down
1 change: 1 addition & 0 deletions script/config/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ local template = {
'assert',
'error',
'type',
'os.exit',
}
),
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',
Expand Down
2 changes: 1 addition & 1 deletion script/core/diagnostics/missing-return.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local await = require 'await'
---@param block parser.object
---@return boolean
local function hasReturn(block)
if block.hasReturn or block.hasError then
if block.hasReturn or block.hasExit then
return true
end
if block.type == 'if' then
Expand Down
2 changes: 1 addition & 1 deletion script/core/diagnostics/unreachable-code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
---@param block parser.object
---@return boolean
local function hasReturn(block)
if block.hasReturn or block.hasError then
if block.hasReturn or block.hasExit then
return true
end
if block.type == 'if' then
Expand Down
6 changes: 4 additions & 2 deletions script/parser/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ local Specials = {
['assert'] = true,
['error'] = true,
['type'] = true,
['os.exit'] = true,
}

local UnarySymbol = {
Expand Down Expand Up @@ -2899,14 +2900,15 @@ local function compileExpAsAction(exp)
end

if exp.type == 'call' then
if exp.node.special == 'error' then
if exp.node.special == 'error'
or exp.node.special == 'os.exit' then
for i = #Chunk, 1, -1 do
local block = Chunk[i]
if block.type == 'ifblock'
or block.type == 'elseifblock'
or block.type == 'elseblock'
or block.type == 'function' then
block.hasError = true
block.hasExit = true
break
end
end
Expand Down
2 changes: 1 addition & 1 deletion script/parser/guide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ local type = type
---@field hasGoTo? true
---@field hasReturn? true
---@field hasBreak? true
---@field hasError? true
---@field hasExit? true
---@field [integer] parser.object|any
---@field package _root parser.object

Expand Down
2 changes: 1 addition & 1 deletion script/vm/tracer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ local lookIntoChild = util.switch()
local neverReturn = subBlock.hasReturn
or subBlock.hasGoTo
or subBlock.hasBreak
or subBlock.hasError
or subBlock.hasExit
if neverReturn then
mergedNode = true
else
Expand Down
11 changes: 11 additions & 0 deletions test/type_inference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2620,6 +2620,17 @@ end
print(<?n?>)
]]

TEST 'integer' [[
---@type integer?
local n
if not n then
os.exit()
end
print(<?n?>)
]]

TEST 'table' [[
---@type table?
local n
Expand Down

0 comments on commit 4b0d634

Please sign in to comment.