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 9package p 10 11//go:notinheap 12type nih struct{} 13 14type embed4 map[nih]int // ERROR "incomplete \(or unallocatable\) map key not allowed" 15 16type embed5 map[int]nih // ERROR "incomplete \(or unallocatable\) map value not allowed" 17 18type emebd6 chan nih // ERROR "chan of incomplete \(or unallocatable\) type not allowed" 19 20type okay1 *nih 21 22type okay2 []nih 23 24type okay3 func(x nih) nih 25 26type okay4 interface { 27 f(x nih) nih 28} 29 30// Type conversions don't let you sneak past notinheap. 31 32type t1 struct{ x int } 33 34//go:notinheap 35type t2 t1 36 37//go:notinheap 38type t3 byte 39 40//go:notinheap 41type t4 rune 42 43var sink interface{} 44 45func i() { 46 sink = new(t1) // no error 47 sink = (*t2)(new(t1)) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)" 48 sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)" 49 sink = []t3("foo") // ERROR "cannot convert(.|\n)*t3 is incomplete \(or unallocatable\)" 50 sink = []t4("bar") // ERROR "cannot convert(.|\n)*t4 is incomplete \(or unallocatable\)" 51} 52