array_elem_addr.mx raw

   1  // The address of an array element is *uint8, not *[N]uint8. stage4 built the
   2  // element address with ssaElemType, which stops at the pointee, so
   3  // `var p *byte = &b.t[1]` was rejected by the assignability check. `byte` is an
   4  // alias for uint8, so this is valid and legacy accepts it. runtime's
   5  // `emptySlotTophash = &bucket.tophash[i]` was the first real site to hit it.
   6  package main
   7  
   8  type B struct{ t [8]uint8 }
   9  
  10  func main() {
  11  	var b B
  12  	var p *byte = &b.t[1]
  13  	*p = 5
  14  	println(b.t[1])
  15  	var q *uint8 = &b.t[2]
  16  	*q = 9
  17  	println(b.t[2])
  18  }
  19