]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/convert4.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / convert4.go
index 2bc9c96a527fa15a9625cec9df3eb444cadccbd5..3cc0aea7be94a85a2a3ee4c965e54906388b5d26 100644 (file)
@@ -23,25 +23,47 @@ func wantPanic(fn func(), s string) {
 
 func main() {
        s := make([]byte, 8, 10)
+       for i := range s {
+               s[i] = byte(i)
+       }
        if p := (*[8]byte)(s); &p[0] != &s[0] {
                panic("*[8]byte conversion failed")
        }
+       if [8]byte(s) != *(*[8]byte)(s) {
+               panic("[8]byte conversion failed")
+       }
        wantPanic(
                func() {
                        _ = (*[9]byte)(s)
                },
-               "runtime error: cannot convert slice with length 8 to pointer to array with length 9",
+               "runtime error: cannot convert slice with length 8 to array or pointer to array with length 9",
+       )
+       wantPanic(
+               func() {
+                       _ = [9]byte(s)
+               },
+               "runtime error: cannot convert slice with length 8 to array or pointer to array with length 9",
        )
 
        var n []byte
        if p := (*[0]byte)(n); p != nil {
                panic("nil slice converted to *[0]byte should be nil")
        }
+       _ = [0]byte(n)
 
        z := make([]byte, 0)
        if p := (*[0]byte)(z); p == nil {
                panic("empty slice converted to *[0]byte should be non-nil")
        }
+       _ = [0]byte(z)
+
+       var p *[]byte
+       wantPanic(
+               func() {
+                       _ = [0]byte(*p) // evaluating *p should still panic
+               },
+               "runtime error: invalid memory address or nil pointer dereference",
+       )
 
        // Test with named types
        type Slice []int