How Tail Calls Work in Go (Spoiler

No TCO)

Go does not support tail call optimization, so tail-recursive functions will consume stack space and may overflow.

Go does not perform tail call optimization (TCO), meaning tail-recursive functions will grow the call stack and eventually cause a stack overflow. Unlike languages like Scheme or Scala, the Go compiler intentionally omits TCO to preserve stack traces for debugging and to simplify the runtime model.

func factorial(n int) int {
    if n <= 1 {
        return 1
    }
    // This is a tail call, but Go will NOT optimize it.
    // Deep recursion here will panic with "runtime: stack overflow".
    return factorial(n-1) * n
}