title: Initialize a custom type doesn't work with var but works with :=
body: <p>I'm trying to initialize an ErrNegativeSqrt, which is a custom float64 type, but if I do it with <code>var</code> it doesn't work.</p>
  
  <p>Take a look in <code>func Sqrt(x float64) (float64, error)</code>:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  type ErrNegativeSqrt float64
  
  func (e *ErrNegativeSqrt) Error() string {
      return fmt.Sprint("cannot Sqrt negative number: %f", float64(*e))
  }
  
  func Sqrt(x float64) (float64, error) {
      if x &lt; 0 {
          var err ErrNegativeSqrt = x
          // This works: err := ErrNegativeSqrt(x)
          return x, &amp;err
      }
  
      z := x / 2
      i := 1
  
      for prev_z := 0.0; z != prev_z &amp;&amp; Abs(z-prev_z) &gt; 0.000000000000001; i++ {
          prev_z = z
          z -= (z*z - x) / (2 * z)
      }
  
      return z, nil
  }
  
  func Abs(x float64) float64 {
      if x &lt; 0 {
          x = -x
      }
      return x
  }
  
  func main() {
      fmt.Println(Sqrt(2))
      fmt.Println(Sqrt(-2))
  }
  </code></pre>
  
  <p>The error is: <code>./prog.go:15:7: cannot use x (type float64) as type ErrNegativeSqrt in assignment</code></p>
  
  <p>Why does it happen? Isn't it the same as the assignment with <code>:=</code>?</p>
  
  <p><a href="https://play.golang.org/p/svMq3Dg4jCa" rel="nofollow noreferrer">Here there is the playground.</a></p>