-2

I have a function named test which is inside the main func.

//stuff

func main() {
  var test = func() {
    if (/*some condition from main*/) {
      return test()
    }
  }

  val := test()
}

When i run this it says:

undefined: test

and it is referencing the return test() inside the test func. How can i fix this?

Ank i zle
  • 2,089
  • 3
  • 14
  • 36

1 Answers1

0

You have to declare the variable before you use it:

var test func()
test=func() {
   if ... {
     test()
   }
}
Burak Serdar
  • 46,455
  • 3
  • 40
  • 59