diff --git a/transpile/service.go b/transpile/service.go index f505a2a..7b247bb 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -106,6 +106,12 @@ func handleBasicLit(bl *ast.BasicLit) string { return bl.Value } +func handleUnaryExpr(expr *ast.UnaryExpr) string { + code := expr.Op.String() + code += handleExpr(expr.X) + return code +} + func handleBinaryExpr(expr ast.Expr) string { be := expr.(*ast.BinaryExpr) code := handleExpr(be.X) @@ -153,6 +159,8 @@ func handleExpr(expr ast.Expr) string { switch e := expr.(type) { case *ast.BasicLit: code += handleBasicLit(e) + case *ast.UnaryExpr: + code += handleUnaryExpr(e) case *ast.BinaryExpr: code += handleBinaryExpr(e) case *ast.CallExpr: diff --git a/transpile/service_test.go b/transpile/service_test.go index a0b2a65..e40cad3 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -573,6 +573,26 @@ var _ = Describe("Go Translator", func() { ` Compare(source, expected) }) + It("Объявление int функции с return -1", func() { + source := `package test + func Setup() {} + func Loop() { + } + + func MyFunction() int { + return -1 + } + ` + expected := ` + void setup() {} + void loop() { + } + MyFunction() { + return -1; + } + ` + Compare(source, expected) + }) It("Объявляет и вызывает функцию", func() { source := `package test func Setup() {}