]> Cypherpunks.ru repositories - gostls13.git/blob - test/fixedbugs/issue31573.go
cmd/compile/internal/typecheck: normalize go/defer statements earlier
[gostls13.git] / test / fixedbugs / issue31573.go
1 // errorcheck -0 -m -l
2
3 // Copyright 2019 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 package p
8
9 func f(...*int) {}
10
11 func g() {
12         defer f()
13         defer f(new(int))           // ERROR "... argument does not escape$" "new\(int\) does not escape$"
14         defer f(new(int), new(int)) // ERROR "... argument does not escape$" "new\(int\) does not escape$"
15
16         defer f(nil...)
17         defer f([]*int{}...)                   // ERROR "\[\]\*int{} does not escape$"
18         defer f([]*int{new(int)}...)           // ERROR "\[\]\*int{...} does not escape$" "new\(int\) does not escape$"
19         defer f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} does not escape$" "new\(int\) does not escape$"
20
21         go f()
22         go f(new(int))           // ERROR "... argument does not escape$" "new\(int\) escapes to heap$"
23         go f(new(int), new(int)) // ERROR "... argument does not escape$" "new\(int\) escapes to heap$"
24
25         go f(nil...)
26         go f([]*int{}...)                   // ERROR "\[\]\*int{} does not escape$"
27         go f([]*int{new(int)}...)           // ERROR "\[\]\*int{...} does not escape$" "new\(int\) escapes to heap$"
28         go f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} does not escape$" "new\(int\) escapes to heap$"
29
30         for {
31                 defer f()
32                 defer f(new(int))           // ERROR "... argument does not escape$" "new\(int\) escapes to heap$"
33                 defer f(new(int), new(int)) // ERROR "... argument does not escape$" "new\(int\) escapes to heap$"
34
35                 defer f(nil...)
36                 defer f([]*int{}...)                   // ERROR "\[\]\*int{} does not escape$"
37                 defer f([]*int{new(int)}...)           // ERROR "\[\]\*int{...} does not escape$" "new\(int\) escapes to heap$"
38                 defer f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} does not escape$" "new\(int\) escapes to heap$"
39
40                 go f()
41                 go f(new(int))           // ERROR "... argument does not escape$" "new\(int\) escapes to heap$"
42                 go f(new(int), new(int)) // ERROR "... argument does not escape$" "new\(int\) escapes to heap$"
43
44                 go f(nil...)
45                 go f([]*int{}...)                   // ERROR "\[\]\*int{} does not escape$"
46                 go f([]*int{new(int)}...)           // ERROR "\[\]\*int{...} does not escape$" "new\(int\) escapes to heap$"
47                 go f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} does not escape$" "new\(int\) escapes to heap$"
48         }
49 }