compiler: correctly handle defer in functions without return values

Fix #2253.
This commit is contained in:
Roman Khimov 2021-11-12 19:30:50 +03:00
parent b31a8d750e
commit a91581fa16
2 changed files with 37 additions and 4 deletions

View file

@ -3,6 +3,8 @@ package compiler_test
import (
"math/big"
"testing"
"github.com/stretchr/testify/require"
)
func TestDefer(t *testing.T) {
@ -79,6 +81,33 @@ func TestDefer(t *testing.T) {
}`
eval(t, src, big.NewInt(13))
})
t.Run("NoReturnReturn", func(t *testing.T) {
src := `package main
var i int
func Main() {
defer func() {
i++
}()
return
}`
vm := vmAndCompile(t, src)
err := vm.Run()
require.NoError(t, err)
require.Equal(t, 0, vm.Estack().Len(), "stack contains unexpected items")
})
t.Run("NoReturnNoReturn", func(t *testing.T) {
src := `package main
var i int
func Main() {
defer func() {
i++
}()
}`
vm := vmAndCompile(t, src)
err := vm.Run()
require.NoError(t, err)
require.Equal(t, 0, vm.Estack().Len(), "stack contains unexpected items")
})
}
func TestRecover(t *testing.T) {