reject_string_array.mx raw

   1  // expected: a fixed extent is not text
   2  //
   3  // A fixed extent is not a slice, so it cannot be converted to text. go/types
   4  // rejects both directions (`string([8]byte)`, `[]byte([8]byte)`) and legacy
   5  // reports "cannot convert ... to type string"; stage4 lowered it as a bitcast
   6  // from `[8 x i8]` to the slice header, which clang refuses:
   7  //
   8  //	error: invalid cast opcode for cast from '[8 x i8]' to '{ ptr, i64, i64 }'
   9  //
  10  // The conversion that exists is `string(buf[:])` - the array becomes a slice
  11  // view first, and then text. `internal/xcoff` is where the rejected shape was
  12  // reached.
  13  package main
  14  
  15  type hdr struct {
  16  	Name [8]byte
  17  }
  18  
  19  func main() {
  20  	var h hdr
  21  	h.Name[0] = 'a'
  22  	println(string(h.Name))
  23  }
  24