// expected: cannot index package main // Only a pointer-to-ARRAY is indexable: p[i] selects an element of the array p // points at. A pointer-to-slice is not, and both compilers used to accept it // because the indexable check recursed into the pointee. // // The cost of accepting it is not hypothetical: image/jpeg's // `qt := &d.quant[d.comp[i].tq]; ...; b[unzig[zig]] *= qt[zig]` was a pointer to // an array in Go and became a pointer to a slice header when block became a // slice. stage4 emitted `mul i32 %value, %slice` and clang rejected the module // with "'%t35' defined with type '{ ptr, i64, i64 }' but expected 'i32'". func f(p *[]byte) (out byte) { return p[0] } func main() { b := []byte{:4} println(f(&b)) }