1 // errorcheck -0 -l -d=defer
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.
7 // check that open-coded defers are used in expected situations
17 for i := 0; i < 10; i++ {
20 defer func() { // ERROR "open-coded defer"
27 defer func() { // ERROR "heap-allocated defer"
34 defer func() { // ERROR "stack-allocated defer"
40 defer func() { // ERROR "stack-allocated defer"
44 defer func() { // ERROR "heap-allocated defer"
54 defer func() { // ERROR "open-coded defer"
58 fmt.Println("goto loop")
66 fmt.Println("goto loop")
67 defer func() { // ERROR "heap-allocated defer"
77 fmt.Println("goto loop")
81 // The current analysis doesn't end a backward goto loop, so this defer is
82 // considered to be inside a loop
83 defer func() { // ERROR "heap-allocated defer"