diff --git a/pkg/compiler/func_scope.go b/pkg/compiler/func_scope.go index d4a0ca862..de9d039e7 100644 --- a/pkg/compiler/func_scope.go +++ b/pkg/compiler/func_scope.go @@ -65,9 +65,11 @@ func (c *funcScope) analyzeVoidCalls(node ast.Node) bool { } } case *ast.ReturnStmt: - switch n.Results[0].(type) { - case *ast.CallExpr: - return false + if len(n.Results) > 0 { + switch n.Results[0].(type) { + case *ast.CallExpr: + return false + } } case *ast.BinaryExpr: return false diff --git a/pkg/compiler/function_call_test.go b/pkg/compiler/function_call_test.go index 7c1f22367..179e0d136 100644 --- a/pkg/compiler/function_call_test.go +++ b/pkg/compiler/function_call_test.go @@ -121,7 +121,14 @@ func TestFunctionWithVoidReturn(t *testing.T) { return x + y } - func getSomeInteger() { } + func getSomeInteger() { %s } ` - eval(t, src, big.NewInt(6)) + t.Run("EmptyBody", func(t *testing.T) { + src := fmt.Sprintf(src, "") + eval(t, src, big.NewInt(6)) + }) + t.Run("SingleReturn", func(t *testing.T) { + src := fmt.Sprintf(src, "return") + eval(t, src, big.NewInt(6)) + }) }