That is the core. Thanks!
So the complier will only search the local variable and assign if there is one named the same, or create a new one if have not been declared. I wrote some code and confirmed it. Here it is.
package main
import (
"fmt"
)
func main() {
test()
}
func test() {
var foo int
fmt.Println(&foo)
foo, err := bar()
if err != nil {
fmt.Println(err)
}
fmt.Println(&foo)
}
func bar() (int, error) {
return 1, nil
}
They print the same address as I expect.