When copying the struct with sync.Mutex, Vet is throwing warning as expected.But when I use the method instead of direct copy, It didn’t throw warning.(toggle the lines to see the behaviors)
// You can edit this code!
// Click here and start typing.
package main
import “fmt”
import “sync”
type person struct {
Name string
initMu sync.Mutex
}
type college struct {
student *person
}
type school struct {
student person
}
func (c *college) getPerson() *person{
return c.student
}
func main() {
name := “student1”
a := person{ Name : name}
col := college { student : &a }
school := school{}
//toggle below two lines
school.student = *col.student
//school.student = *col.getPerson()
fmt.Println(school.student.Name)
fmt.Printf("%p\n", &a)
fmt.Printf("%p\n", col.student)
fmt.Printf("%p\n", col.getPerson())
fmt.Printf("%p\n", &school.student)
col.student.Name = "student2"
fmt.Println(school.student.Name)
}