summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-03-09 14:54:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-03-09 14:54:49 +0800
commita9fe326bb74a35501748fe1b265d9dbf268cfe88 (patch)
tree89c275f7367d2af2c431623318444ec1ac7c5a8e /script
parentd7d44a727087337638b3fe8ff0a45a12945b2d03 (diff)
downloadlua-language-server-a9fe326bb74a35501748fe1b265d9dbf268cfe88.zip
support `x or error(...)`
fix #1945
Diffstat (limited to 'script')
-rw-r--r--script/parser/compile.lua27
-rw-r--r--script/vm/operator.lua5
2 files changed, 19 insertions, 13 deletions
diff --git a/script/parser/compile.lua b/script/parser/compile.lua
index 917a68a4..a33fe09b 100644
--- a/script/parser/compile.lua
+++ b/script/parser/compile.lua
@@ -1974,6 +1974,12 @@ local function parseSimple(node, funcName)
and node.node == lastMethod then
lastMethod = nil
end
+ if node.type == 'call' then
+ if node.node.special == 'error'
+ or node.node.special == 'os.exit' then
+ node.hasExit = true
+ end
+ end
if node == lastMethod then
if funcName then
lastMethod = nil
@@ -2899,18 +2905,15 @@ local function compileExpAsAction(exp)
end
end
- if exp.type == 'call' 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.hasExit = true
- break
- end
+ if exp.hasExit 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.hasExit = true
+ break
end
end
return exp
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index cb27d33d..b2a3aa10 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -199,7 +199,10 @@ vm.binarySwitch = util.switch()
elseif r1 == false then
vm.setNode(source, node2)
else
- local node = node1:copy():setTruthy():merge(node2)
+ local node = node1:copy():setTruthy()
+ if not source[2].hasExit then
+ node:merge(node2)
+ end
vm.setNode(source, node)
end
end)