mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: clean up stack on branch statements
When `return` or `break` statement is encountered inside a for/range/switch statement, top stack items can be auxilliary. They need to be cleaned up before returning from the function.
This commit is contained in:
parent
3f1e8f66b6
commit
2a1402f25d
3 changed files with 63 additions and 2 deletions
|
@ -23,10 +23,17 @@ func runTestCases(t *testing.T, tcases []testCase) {
|
|||
}
|
||||
}
|
||||
|
||||
func evalWithoutStackChecks(t *testing.T, src string, result interface{}) {
|
||||
v := vmAndCompile(t, src)
|
||||
require.NoError(t, v.Run())
|
||||
assertResult(t, v, result)
|
||||
}
|
||||
|
||||
func eval(t *testing.T, src string, result interface{}) {
|
||||
vm := vmAndCompile(t, src)
|
||||
err := vm.Run()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, vm.Estack().Len(), "stack contains unexpected items")
|
||||
assertResult(t, vm, result)
|
||||
}
|
||||
|
||||
|
@ -35,6 +42,7 @@ func evalWithArgs(t *testing.T, src string, op []byte, args []vm.StackItem, resu
|
|||
vm.LoadArgs(op, args)
|
||||
err := vm.Run()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, vm.Estack().Len(), "stack contains unexpected items")
|
||||
assertResult(t, vm, result)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue