I would like to know why there is no warning or error in the following code which allows me to override a global variable.
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
type MyStruct struct {
MyInt uint32
}
func (s *MyStruct) MyMethod() {
fmt.Println(s.MyInt)
}
var theStruct MyStruct
func main() {
// Override the above global variable
// I would expect some kind of warning or error here?
theStruct := MyStruct {
MyInt: 42,
}
// Outputs 42
theStruct.MyMethod()
// Outputs 0
UseMyStruct()
}
func UseMyStruct() {
theStruct.MyMethod()
}