1. Support unparam linter and fix found issues
2. Replace forked mvdan.cc/lint and mvdan.cc/interfacer with the
upstream ones
3. Minimize forked megacheck: move the most of it's code to this repo
4. Use golang.org/x/tools/go/ssa import path instead of custom fork
paths
5. In golang.org/x/tools/go/{ssa,callgraph} use changed code from
honnef.co/go/tools
6. Add megacheck.check-unexported option: it found some issues in
the repo, fixed them all
25 lines
582 B
Go
25 lines
582 B
Go
package functions
|
|
|
|
import "golang.org/x/tools/go/ssa"
|
|
|
|
// terminates reports whether fn is supposed to return, that is if it
|
|
// has at least one theoretic path that returns from the function.
|
|
// Explicit panics do not count as terminating.
|
|
func terminates(fn *ssa.Function) bool {
|
|
if fn.Blocks == nil {
|
|
// assuming that a function terminates is the conservative
|
|
// choice
|
|
return true
|
|
}
|
|
|
|
for _, block := range fn.Blocks {
|
|
if len(block.Instrs) == 0 {
|
|
continue
|
|
}
|
|
if _, ok := block.Instrs[len(block.Instrs)-1].(*ssa.Return); ok {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|