Skip to content

Instantly share code, notes, and snippets.

@JPMoresmau
Created January 29, 2019 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPMoresmau/ed8da9eeda3286629eaf01d1e7b520a7 to your computer and use it in GitHub Desktop.
Save JPMoresmau/ed8da9eeda3286629eaf01d1e7b520a7 to your computer and use it in GitHub Desktop.
Showing variable shadowing gotcha
import (
"fmt"
"errors"
)
func main() {
var err error
var doIt = true
if doIt {
ret, err := mayError()
if err == nil {
fmt.Printf("%s",ret)
}
}
fmt.Printf("%t", err == nil)
}
func mayError() (string, error) {
return "",errors.New("failed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment