Why doesn't the following code panic? test
is definitely a pointer. With fmt.Println(people[0].Name)
instead of fmt.Println(test.Name)
it does panic.
package main
import "fmt"
func main() {
type Person struct {
Id int
Name string
}
people := make(map[int]*Person)
people[1] = &Person{0, "Name"}
fmt.Println(people[0].Name)
test := people[0]
test.Name = "Name2"
fmt.Println(test.Name)
people[0].Name = "Name3"
fmt.Println(test.Name)
delete(people, 0)
fmt.Println(test.Name)
}