From 29538be083aedadbb26cf3e84ec240aa4ae27157 Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 4 Oct 2021 02:29:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20return=20=D0=B8=D0=B7=20void=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile/service.go | 4 +++- transpile/service_test.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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() {}