2020-05-24 20:49:49 +02:00
|
|
|
package fixtures
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
type tt int
|
|
|
|
|
|
|
|
func (t tt) m() {}
|
|
|
|
|
|
|
|
func deferrer() {
|
|
|
|
for {
|
|
|
|
go func() {
|
|
|
|
defer println()
|
|
|
|
}()
|
|
|
|
defer func() {}() // MATCH /prefer not to defer inside loops/
|
|
|
|
}
|
|
|
|
|
|
|
|
defer tt.m() // MATCH /be careful when deferring calls to methods without pointer receiver/
|
|
|
|
|
|
|
|
defer func() error {
|
2022-07-24 00:34:16 -07:00
|
|
|
return errors.New("error") // MATCH /return in a defer function has no effect/
|
2020-05-24 20:49:49 +02:00
|
|
|
}()
|
|
|
|
|
2022-07-24 00:34:16 -07:00
|
|
|
defer recover() // MATCH /recover must be called inside a deferred function, this is executing recover immediately/
|
2020-05-24 20:49:49 +02:00
|
|
|
|
2022-07-24 00:34:16 -07:00
|
|
|
recover() // MATCH /recover must be called inside a deferred function/
|
2020-05-24 20:49:49 +02:00
|
|
|
|
|
|
|
defer deferrer()
|
2022-07-24 00:34:16 -07:00
|
|
|
|
|
|
|
helper := func(_ interface{}) {}
|
|
|
|
|
|
|
|
defer helper(recover()) // MATCH /recover must be called inside a deferred function, this is executing recover immediately/
|
|
|
|
|
|
|
|
// does not work, but not currently blocked.
|
|
|
|
defer helper(func() { recover() })
|
2020-05-24 20:49:49 +02:00
|
|
|
}
|