Created
March 28, 2025 09:01
-
-
Save dacr/ea48f376befb8b842419a9cb047a1ec7 to your computer and use it in GitHub Desktop.
go shadowing / published by https://github.com/dacr/code-examples-manager #928f07eb-e5e7-4bdc-859c-ddf0dc3fd729/e4bc20ce10b84026c0cb019d7f164f0396fc0e6a
This file contains hidden or 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
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/ | |
// summary : go shadowing | |
// keywords : go, shadowing, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 928f07eb-e5e7-4bdc-859c-ddf0dc3fd729 | |
// created-on : 2025-03-27T10:46:26+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : nix-shell -p go --run "go run $file" | |
package main | |
import ( | |
"fmt" | |
) | |
func shadowingExample() { | |
toto := "toto" | |
if true { | |
//toto = "titi" // change the upper variable | |
toto := "titi" // new toto variable ! shadowing the previous one | |
fmt.Println(toto) | |
} | |
fmt.Println(toto) | |
} | |
func main() { | |
shadowingExample() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment