]> Cypherpunks.ru repositories - gostls13.git/blob - test/fixedbugs/notinheap.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / fixedbugs / notinheap.go
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 type embed4 map[nih]int // ERROR "incomplete \(or unallocatable\) map key not allowed"
15
16 type embed5 map[int]nih // ERROR "incomplete \(or unallocatable\) map value not allowed"
17
18 type emebd6 chan nih // ERROR "chan of incomplete \(or unallocatable\) type not allowed"
19
20 type okay1 *nih
21
22 type okay2 []nih
23
24 type okay3 func(x nih) nih
25
26 type okay4 interface {
27         f(x nih) nih
28 }
29
30 // Type conversions don't let you sneak past notinheap.
31
32 type t1 struct{ x int }
33
34 //go:notinheap
35 type t2 t1
36
37 //go:notinheap
38 type t3 byte
39
40 //go:notinheap
41 type t4 rune
42
43 var sink interface{}
44
45 func 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 }