Created
January 29, 2019 21:02
-
-
Save JPMoresmau/ed8da9eeda3286629eaf01d1e7b520a7 to your computer and use it in GitHub Desktop.
Showing variable shadowing gotcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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