package main
var a string
func main() {
a = "G"
print(a)
f1()
}
func f1() {
a := "O"
print(a)
f2()
}
func f2() {
print(a)
}
I think f2
will be in f1
's block when call f2
in f1
, so the output will be GOO
, but the output is GOG
instead.
The scope of a type identifier declared inside a function begins at the identifier in the TypeSpec and ends at the end of the innermost containing block. -- From https://golang.org/ref/spec#Declarations_and_scope
What are containing blocks inside a function?
Why another function is not containing block?