modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/notinheap.go (about) 1 // errorcheck -+ 2 3 // Copyright 2016 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. 6 7 // Test type-checking errors for go:notinheap. 8 9 package p 10 11 //go:notinheap 12 type nih struct{} 13 14 // Types embedding notinheap types must be notinheap. 15 16 type embed1 struct { // ERROR "must be go:notinheap" 17 x nih 18 } 19 20 type embed2 [1]nih // ERROR "must be go:notinheap" 21 22 type embed3 struct { // ERROR "must be go:notinheap" 23 x [1]nih 24 } 25 26 type embed4 map[nih]int // ERROR "go:notinheap map key not allowed" 27 28 type embed5 map[int]nih // ERROR "go:notinheap map value not allowed" 29 30 type emebd6 chan nih // ERROR "chan of go:notinheap type not allowed" 31 32 type okay1 *nih 33 34 type okay2 []nih 35 36 type okay3 func(x nih) nih 37 38 type okay4 interface { 39 f(x nih) nih 40 } 41 42 // Type conversions don't let you sneak past notinheap. 43 44 type t1 struct{ x int } 45 46 //go:notinheap 47 type t2 t1 48 49 var sink interface{} 50 51 func i() { 52 sink = new(t1) // no error 53 sink = (*t2)(new(t1)) // ERROR "cannot convert(.|\n)*t2 is go:notinheap" 54 sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is go:notinheap" 55 }