This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
packagefunctions
import(
"go/types"
"honnef.co/go/tools/ir"
)
// 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.
funcTerminates(fn*ir.Function)bool{
iffn.Blocks==nil{
// assuming that a function terminates is the conservative
// choice
returntrue
}
for_,block:=rangefn.Blocks{
if_,ok:=block.Control().(*ir.Return);ok{
iflen(block.Preds)==0{
returntrue
}
for_,pred:=rangeblock.Preds{
switchctrl:=pred.Control().(type){
case*ir.Panic:
// explicit panics do not count as terminating
case*ir.If:
// Check if we got here by receiving from a closed
// time.Tick channel – this cannot happen at
// runtime and thus doesn't constitute termination