title: Go code doesn't compile without an unreachable return statement
body: <p>Here is the program to find the factorial of a number in Go: </p>
  
  <pre><code>func factorial(x uint) uint {
      if x == 0 {
          return 1
      }
  
      return x * (factorial(x - 1))
  }
  </code></pre>
  
  <p>The output for this function when called on input 5 is 120. However, if I add an <code>else</code> statement I get an error.</p>
  
  <pre><code>func factorial(x uint) uint {
      if x == 0 {
          return 1
      } else {
          return x * (factorial(x - 1))
      }
  }
  </code></pre>
  
  <p>Error : <code>function ends without a return statement</code></p>
  
  <p>I added a <code>return</code> at the end :</p>
  
  <pre><code>func factorial(x uint) uint {
      if x == 0 {
          return 1
      } else {
          return x * (factorial(x - 1))
      }
      fmt.Println("this never executes")
      return 1
  }
  </code></pre>
  
  <p>and I get back the expected output of 120.</p>
  
  <p>Why would the second case cause an error? Why in the third case even though the function never reaches the last <code>return 1</code>, it computes the correct output?</p>