mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: support using return
in some branches
When `return` is used in one codepath, but not the other, we do not clean altstack properly. This commit fixes it.
This commit is contained in:
parent
770cff8b91
commit
156a2eddc5
3 changed files with 37 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
@ -132,3 +133,28 @@ func TestFunctionWithVoidReturn(t *testing.T) {
|
|||
eval(t, src, big.NewInt(6))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFunctionWithVoidReturnBranch(t *testing.T) {
|
||||
src := `
|
||||
package testcase
|
||||
func Main() int {
|
||||
x := %t
|
||||
f(x)
|
||||
return 2
|
||||
}
|
||||
|
||||
func f(x bool) {
|
||||
if x {
|
||||
return
|
||||
}
|
||||
}
|
||||
`
|
||||
t.Run("ReturnBranch", func(t *testing.T) {
|
||||
src := fmt.Sprintf(src, true)
|
||||
eval(t, src, big.NewInt(2))
|
||||
})
|
||||
t.Run("NoReturn", func(t *testing.T) {
|
||||
src := fmt.Sprintf(src, false)
|
||||
eval(t, src, big.NewInt(2))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue