diff --git a/transpile/service.go b/transpile/service.go index 20bc8ab..0252634 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -311,9 +311,6 @@ func handleFuncDecl(decl ast.Decl) string { fp := handleFuncDeclParams(fd.Type) code += fp - if ft == "" { - ft = "int" - } addFunctionDeclaration(ft + " " + name + "(" + fp + ");") code += ") {" @@ -417,8 +414,19 @@ func handleFuncDeclName(ident *ast.Ident) string { func handleFuncDeclType(t *ast.FuncType) string { code := "" if t.Results == nil { - code = "void" + return "void" } + + fl := t.Results + if fl.NumFields() == 0 { + panic("handleFuncDeclType: fl.NumFields() == 0") + } + + switch ft := fl.List[0].Type.(type) { + case *ast.Ident: + code += handleIdent(ft) + } + return code } diff --git a/transpile/service_test.go b/transpile/service_test.go index 235a70d..1fc8adb 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -283,7 +283,7 @@ var _ = Describe("Go Translator", func() { void foo() { foo2(); } - foo2() { + int foo2() { return 0; } ` @@ -708,7 +708,7 @@ var _ = Describe("Go Translator", func() { void setup() {} void loop() { } - MyFunction() { + int MyFunction() { } ` Compare(source, expected) @@ -731,7 +731,7 @@ var _ = Describe("Go Translator", func() { void setup() {} void loop() { } - MyFunction() { + int MyFunction() { return 0; } ` @@ -755,7 +755,7 @@ var _ = Describe("Go Translator", func() { void setup() {} void loop() { } - MyFunction() { + int MyFunction() { return -1; } ` @@ -781,12 +781,27 @@ var _ = Describe("Go Translator", func() { void loop() { int x = MyFunction(); } - MyFunction() { + int MyFunction() { return 0; } ` Compare(source, expected) }) + It("Объявление bool функции с return false", func() { + source := `package test + func MyFunction() bool { + return false + } + ` + expected := ` + bool MyFunction(); + + bool MyFunction() { + return false; + } + ` + Compare(source, expected) + }) }) Describe("Циклы", func() {