reject_global_mutation_closure.mx raw

   1  // expected: package globals are immutable outside init
   2  //
   3  // A package global may only be written by init()/__varinit. stage4's check
   4  // walked package members, so a store inside a function literal was never
   5  // visited: the same assignment compiled cleanly when wrapped in a closure.
   6  // Legacy rejects both, because the rule is a property of the store, not of
   7  // where the enclosing declaration happens to sit.
   8  package main
   9  
  10  var calls int32
  11  
  12  func main() {
  13  	f := func() (r int32) {
  14  		calls = calls + 1
  15  		return calls
  16  	}
  17  	println(f())
  18  }
  19