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:
Evgenii Stratonikov 2020-05-06 15:39:25 +03:00
parent 770cff8b91
commit 156a2eddc5
3 changed files with 37 additions and 12 deletions

View file

@ -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))
})
}