>even if that code has visible side effects
The argument is that you told it to do that. "Just print whenever", and whenever can mean never if the world dies prematurely.
The argument is that you told it to do that. "Just print whenever", and whenever can mean never if the world dies prematurely.
And by that argument, since main() itself is an implicitly-called goroutine (so far as I know), then the compiler can elide the entire contents of main() too, and then the rest of the contents of the program.
</reductio-ad-absurdum>
func main() {
go fmt.Println("Hi!")
}
This is a valid go program (eliding import etc), and it'll almost never print anything.This is actually a classic mistake when starting with goroutines - not adding synchronization to make sure your main goroutine doesn't exit before any spawned goroutines.