Skip to content

Commit 4b0d634

Browse files
committed
fix #1889
1 parent 5e112de commit 4b0d634

File tree

8 files changed

+22
-6
lines changed

8 files changed

+22
-6
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* `CHG` completion: don't show loading process
55
* `FIX` [#1886]
66
* `FIX` [#1895]
7+
* `FIX` [#1889]
78

89
[#1886]: https://github.com/LuaLS/lua-language-server/issues/1886
910
[#1895]: https://github.com/LuaLS/lua-language-server/issues/1895
11+
[#1889]: https://github.com/LuaLS/lua-language-server/issues/1889
1012

1113
## 3.6.10
1214
`2023-2-7`

script/config/template.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ local template = {
210210
'assert',
211211
'error',
212212
'type',
213+
'os.exit',
213214
}
214215
),
215216
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',

script/core/diagnostics/missing-return.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local await = require 'await'
77
---@param block parser.object
88
---@return boolean
99
local function hasReturn(block)
10-
if block.hasReturn or block.hasError then
10+
if block.hasReturn or block.hasExit then
1111
return true
1212
end
1313
if block.type == 'if' then

script/core/diagnostics/unreachable-code.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
---@param block parser.object
2424
---@return boolean
2525
local function hasReturn(block)
26-
if block.hasReturn or block.hasError then
26+
if block.hasReturn or block.hasExit then
2727
return true
2828
end
2929
if block.type == 'if' then

script/parser/compile.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ local Specials = {
118118
['assert'] = true,
119119
['error'] = true,
120120
['type'] = true,
121+
['os.exit'] = true,
121122
}
122123

123124
local UnarySymbol = {
@@ -2899,14 +2900,15 @@ local function compileExpAsAction(exp)
28992900
end
29002901

29012902
if exp.type == 'call' then
2902-
if exp.node.special == 'error' then
2903+
if exp.node.special == 'error'
2904+
or exp.node.special == 'os.exit' then
29032905
for i = #Chunk, 1, -1 do
29042906
local block = Chunk[i]
29052907
if block.type == 'ifblock'
29062908
or block.type == 'elseifblock'
29072909
or block.type == 'elseblock'
29082910
or block.type == 'function' then
2909-
block.hasError = true
2911+
block.hasExit = true
29102912
break
29112913
end
29122914
end

script/parser/guide.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ local type = type
7272
---@field hasGoTo? true
7373
---@field hasReturn? true
7474
---@field hasBreak? true
75-
---@field hasError? true
75+
---@field hasExit? true
7676
---@field [integer] parser.object|any
7777
---@field package _root parser.object
7878

script/vm/tracer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ local lookIntoChild = util.switch()
369369
local neverReturn = subBlock.hasReturn
370370
or subBlock.hasGoTo
371371
or subBlock.hasBreak
372-
or subBlock.hasError
372+
or subBlock.hasExit
373373
if neverReturn then
374374
mergedNode = true
375375
else

test/type_inference/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,17 @@ end
26202620
print(<?n?>)
26212621
]]
26222622

2623+
TEST 'integer' [[
2624+
---@type integer?
2625+
local n
2626+
2627+
if not n then
2628+
os.exit()
2629+
end
2630+
2631+
print(<?n?>)
2632+
]]
2633+
26232634
TEST 'table' [[
26242635
---@type table?
26252636
local n

0 commit comments

Comments
 (0)