blob: 44b79646ef70ca62093fbffbc3072374e971e488 [file] [log] [blame]
Austin Clements77527a32016-10-11 22:53:27 -04001// 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
14// Types embedding notinheap types must be notinheap.
15
Matthew Dempskya27b7812017-02-01 12:35:53 -080016type embed1 struct { // ERROR "must be go:notinheap"
Austin Clements77527a32016-10-11 22:53:27 -040017 x nih
Matthew Dempskya27b7812017-02-01 12:35:53 -080018}
Austin Clements77527a32016-10-11 22:53:27 -040019
20type embed2 [1]nih // ERROR "must be go:notinheap"
21
Matthew Dempskya27b7812017-02-01 12:35:53 -080022type embed3 struct { // ERROR "must be go:notinheap"
Austin Clements77527a32016-10-11 22:53:27 -040023 x [1]nih
Matthew Dempskya27b7812017-02-01 12:35:53 -080024}
Austin Clements77527a32016-10-11 22:53:27 -040025
26type embed4 map[nih]int // ERROR "go:notinheap map key not allowed"
27
28type embed5 map[int]nih // ERROR "go:notinheap map value not allowed"
29
30type emebd6 chan nih // ERROR "chan of go:notinheap type not allowed"
31
32type okay1 *nih
33
34type okay2 []nih
35
36type okay3 func(x nih) nih
37
38type okay4 interface {
39 f(x nih) nih
40}
41
42// Type conversions don't let you sneak past notinheap.
43
44type t1 struct{ x int }
45
46//go:notinheap
47type t2 t1
48
49var sink interface{}
50
51func 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}