// Regression: the missing-return check must accept every terminating shape. // // The check mirrors go/types' isTerminating, so an over-strict version would // reject valid code - and for the stdlib that means the compiler cannot build // itself. Each function below is a terminating statement go/types accepts; the // loop forms are never called, they only have to compile and be seen as // complete. The nested-switch case is the subtle one: the unlabelled break // belongs to the switch, not to the surrounding for, so the for still // terminates. package main func ifElse(b bool) (r int32) { if b { return 1 } else { return 2 } } func infiniteFor() (r int32) { n := int32(0) for { n++ if n > 2 { return n } } } func switchDefault(x int32) (r int32) { switch x { case 1: return 1 default: return 2 } } func nestedSwitchBreak() (r int32) { for { switch 1 { case 1: break } } } func panicOnly() (r int32) { panic("unreachable") } func main() { if ifElse(true) != 1 { panic("if/else") } if infiniteFor() != 3 { panic("infinite for") } if switchDefault(9) != 2 { panic("switch default") } println("ok") }