github.com/pankona/gometalinter@v2.0.11+incompatible/_linters/src/honnef.co/go/tools/functions/terminates.go (about)

     1  package functions
     2  
     3  import "honnef.co/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  }