3 // Copyright 2020 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test conversion from slice to array pointer.
11 func wantPanic(fn func(), s string) {
15 panic("expected panic")
17 if got := err.(error).Error(); got != s {
18 panic("expected panic " + s + " got " + got)
25 s := make([]byte, 8, 10)
29 if p := (*[8]byte)(s); &p[0] != &s[0] {
30 panic("*[8]byte conversion failed")
32 if [8]byte(s) != *(*[8]byte)(s) {
33 panic("[8]byte conversion failed")
39 "runtime error: cannot convert slice with length 8 to array or pointer to array with length 9",
45 "runtime error: cannot convert slice with length 8 to array or pointer to array with length 9",
49 if p := (*[0]byte)(n); p != nil {
50 panic("nil slice converted to *[0]byte should be nil")
55 if p := (*[0]byte)(z); p == nil {
56 panic("empty slice converted to *[0]byte should be non-nil")
63 _ = [0]byte(*p) // evaluating *p should still panic
65 "runtime error: invalid memory address or nil pointer dereference",
68 // Test with named types
73 if p := (*Int4)(ii); &p[0] != &ii[0] {
74 panic("*Int4 conversion failed")
76 if p := PInt4(ii); &p[0] != &ii[0] {
77 panic("PInt4 conversion failed")
81 // test static variable conversion
84 ss = make([]string, 10)
86 s10 = (*[10]string)(ss)
89 ns0 = (*[0]string)(ns)
91 zs = make([]string, 0)
92 zs0 = (*[0]string)(zs)
97 panic("s5 conversion failed")
99 if &ss[0] != &s10[0] {
100 panic("s5 conversion failed")
103 panic("ns0 should be nil")
106 panic("zs0 should not be nil")