Skip to content

Commit a9fe326

Browse files
committed
support x or error(...)
fix #1945
1 parent d7d44a7 commit a9fe326

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

Diff for: changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* `FIX` [#1922]
99
* `FIX` [#1924]
1010
* `FIX` [#1928]
11+
* `FIX` [#1945]
1112

1213
[#1715]: https://github.com/LuaLS/lua-language-server/issues/1715
1314
[#1753]: https://github.com/LuaLS/lua-language-server/issues/1753
1415
[#1914]: https://github.com/LuaLS/lua-language-server/issues/1914
1516
[#1922]: https://github.com/LuaLS/lua-language-server/issues/1922
1617
[#1924]: https://github.com/LuaLS/lua-language-server/issues/1924
1718
[#1928]: https://github.com/LuaLS/lua-language-server/issues/1928
19+
[#1945]: https://github.com/LuaLS/lua-language-server/issues/1945
1820

1921
## 3.6.13
2022
`2023-3-2`

Diff for: script/parser/compile.lua

+15-12
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,12 @@ local function parseSimple(node, funcName)
19741974
and node.node == lastMethod then
19751975
lastMethod = nil
19761976
end
1977+
if node.type == 'call' then
1978+
if node.node.special == 'error'
1979+
or node.node.special == 'os.exit' then
1980+
node.hasExit = true
1981+
end
1982+
end
19771983
if node == lastMethod then
19781984
if funcName then
19791985
lastMethod = nil
@@ -2899,18 +2905,15 @@ local function compileExpAsAction(exp)
28992905
end
29002906
end
29012907

2902-
if exp.type == 'call' then
2903-
if exp.node.special == 'error'
2904-
or exp.node.special == 'os.exit' then
2905-
for i = #Chunk, 1, -1 do
2906-
local block = Chunk[i]
2907-
if block.type == 'ifblock'
2908-
or block.type == 'elseifblock'
2909-
or block.type == 'elseblock'
2910-
or block.type == 'function' then
2911-
block.hasExit = true
2912-
break
2913-
end
2908+
if exp.hasExit then
2909+
for i = #Chunk, 1, -1 do
2910+
local block = Chunk[i]
2911+
if block.type == 'ifblock'
2912+
or block.type == 'elseifblock'
2913+
or block.type == 'elseblock'
2914+
or block.type == 'function' then
2915+
block.hasExit = true
2916+
break
29142917
end
29152918
end
29162919
return exp

Diff for: script/vm/operator.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ vm.binarySwitch = util.switch()
199199
elseif r1 == false then
200200
vm.setNode(source, node2)
201201
else
202-
local node = node1:copy():setTruthy():merge(node2)
202+
local node = node1:copy():setTruthy()
203+
if not source[2].hasExit then
204+
node:merge(node2)
205+
end
203206
vm.setNode(source, node)
204207
end
205208
end)

Diff for: test/type_inference/init.lua

+6
Original file line numberDiff line numberDiff line change
@@ -4233,3 +4233,9 @@ function A:func()
42334233
self.y = self.y + 3
42344234
end
42354235
]]
4236+
4237+
TEST 'number' [[
4238+
---@type number?
4239+
local n
4240+
local <?v?> = n or error('')
4241+
]]

0 commit comments

Comments
 (0)