github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/functions/terminates.go (about) 1 package functions 2 3 import "github.com/golangci/go-tools/ssa" 4 5 // terminates reports whether fn is supposed to return, that is if it 6 // has at least one theoretic path that returns from the function. 7 // Explicit panics do not count as terminating. 8 func terminates(fn *ssa.Function) bool { 9 if fn.Blocks == nil { 10 // assuming that a function terminates is the conservative 11 // choice 12 return true 13 } 14 15 for _, block := range fn.Blocks { 16 if len(block.Instrs) == 0 { 17 continue 18 } 19 if _, ok := block.Instrs[len(block.Instrs)-1].(*ssa.Return); ok { 20 return true 21 } 22 } 23 return false 24 }