github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/staticcheck/testdata/CheckInfiniteRecursion.go (about) 1 package pkg 2 3 func fn1(x int) bool { 4 println(x) 5 return fn1(x + 1) // MATCH /infinite recursive call/ 6 return true 7 } 8 9 func fn2(x int) bool { 10 println(x) 11 if x > 10 { 12 return true 13 } 14 return fn2(x + 1) 15 } 16 17 func fn3(x int) bool { 18 println(x) 19 if x > 10 { 20 goto l1 21 } 22 return fn3(x + 1) 23 l1: 24 println(x) 25 return true 26 } 27 28 func fn4(p *int, n int) { 29 if n == 0 { 30 return 31 } 32 x := 0 33 fn4(&x, n-1) 34 if x != n { 35 panic("stack is corrupted") 36 } 37 } 38 39 func fn5(p *int, n int) { 40 x := 0 41 fn5(&x, n-1) // MATCH /infinite recursive call/ 42 if x != n { 43 panic("stack is corrupted") 44 } 45 } 46 47 type T struct { 48 n int 49 } 50 51 func (t T) Fn1() { 52 t.Fn1() // MATCH /infinite recursive call/ 53 } 54 55 func (t T) Fn2() { 56 x := T{} 57 x.Fn2() // MATCH /infinite recursive call/ 58 } 59 60 func (t T) Fn3() { 61 if t.n == 0 { 62 return 63 } 64 t.Fn1() 65 }