mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00
Fix try/catch would not pop excess scopes (#3216)
* Fix try/catch would not pop excess scopes * Set scope directly * Add test
This commit is contained in:
parent
a14a2c7b78
commit
1c14312b14
40
data/expression2/tests/regressions/3080.txt
Normal file
40
data/expression2/tests/regressions/3080.txt
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
## SHOULD_PASS:EXECUTE
|
||||||
|
@strict
|
||||||
|
|
||||||
|
try {
|
||||||
|
error("A")
|
||||||
|
} catch(A:string) {
|
||||||
|
assert(A == "A")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(1) {
|
||||||
|
error("B")
|
||||||
|
}
|
||||||
|
} catch(B:string) {
|
||||||
|
assert(B == "B")
|
||||||
|
}
|
||||||
|
|
||||||
|
if(1) {
|
||||||
|
try {
|
||||||
|
error("C")
|
||||||
|
} catch(C:string) {
|
||||||
|
assert(C == "C")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(1) {
|
||||||
|
error("D")
|
||||||
|
}
|
||||||
|
} catch(D:string) {
|
||||||
|
assert(D == "D")
|
||||||
|
}
|
||||||
|
|
||||||
|
let Fn = function() { error("F") }
|
||||||
|
|
||||||
|
try {
|
||||||
|
Fn()
|
||||||
|
} catch(F:string) {
|
||||||
|
assert(F == "F")
|
||||||
|
}
|
||||||
|
}
|
@ -621,10 +621,13 @@ local CompileVisitors = {
|
|||||||
self.scope.data.ops = self.scope.data.ops + 5
|
self.scope.data.ops = self.scope.data.ops + 5
|
||||||
|
|
||||||
return function(state) ---@param state RuntimeContext
|
return function(state) ---@param state RuntimeContext
|
||||||
|
local scope, scope_id = state.Scope, state.ScopeID
|
||||||
state:PushScope()
|
state:PushScope()
|
||||||
local ok, err = pcall(try_block, state)
|
local ok, err = pcall(try_block, state)
|
||||||
state:PopScope()
|
if ok then
|
||||||
if not ok then
|
state:PopScope()
|
||||||
|
else
|
||||||
|
state.Scope, state.ScopeID = scope, scope_id -- Skip back any scopes that may have been created in try_block
|
||||||
local catchable, msg = E2Lib.unpackException(err)
|
local catchable, msg = E2Lib.unpackException(err)
|
||||||
if catchable then
|
if catchable then
|
||||||
state:PushScope()
|
state:PushScope()
|
||||||
|
Loading…
Reference in New Issue
Block a user