title: Redeclare a variable for convenience in golang?
body: <p>This code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  func main() {
      fmt.Println("Hello, playground")
  
      var a bool
      var b interface{}
      b = true
      if a, ok := b.(bool); !ok {
          fmt.Println("Problem!")
      }
  }
  </code></pre>
  
  <p>Yields this error in the golang playground:</p>
  
  <pre><code>tmp/sandbox791966413/main.go:11:10: a declared and not used
  tmp/sandbox791966413/main.go:14:21: a declared and not used
  </code></pre>
  
  <p>This is confusing because of what we read in the short variable declaration <a href="https://golang.org/ref/spec#Short_variable_declarations" rel="nofollow noreferrer">golang docs</a>:</p>
  
  <blockquote>
    <p>Unlike regular variable declarations, a short variable declaration may
    redeclare variables provided they were originally declared earlier in
    the same block (or the parameter lists if the block is the function
    body) with the same type, and at least one of the non-blank variables
    is new. As a consequence, redeclaration can only appear in a
    multi-variable short declaration. Redeclaration does not introduce a
    new variable; it just assigns a new value to the original.</p>
  </blockquote>
  
  <p>So, my questions:</p>
  
  <ol>
  <li>Why can't I redeclare the variable in the code snippet above?</li>
  <li><p>Supposing I really can't, what I'd <em>really</em> like to do is find
  a way to populate variables with the output of functions while
  checking the error in a more concise way. So <strong>is there any way 
  to improve on the following form for getting a value out of an
  error-able function?</strong></p>
  
  <pre><code>var A RealType
  if newA, err := SomeFunc(); err != nil {
      return err
  } else {
      A = newA
  }   
  </code></pre></li>
  </ol>