diff --git a/transpile/service.go b/transpile/service.go index 50950d4..157833a 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -405,7 +405,9 @@ func handleSwitchStmt(stmt *ast.SwitchStmt) string { func handleReturnStmt(stmt *ast.ReturnStmt) string { code := "return " - code += handleExpr(stmt.Results[0]) + if len(stmt.Results) > 0 { + code += handleExpr(stmt.Results[0]) + } code += ";" return code } diff --git a/transpile/service_test.go b/transpile/service_test.go index b9bf363..8b502d1 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -505,6 +505,26 @@ var _ = Describe("Go Translator", func() { ` Compare(source, expected) }) + It("Объявление void функции с return", func() { + source := `package test + func Setup() {} + func Loop() { + } + + func MyFunction() { + return + } + ` + expected := ` + void setup() {} + void loop() { + } + void MyFunction() { + return; + } + ` + Compare(source, expected) + }) It("Объявление int функции", func() { source := `package test func Setup() {}