}
func f(int) {} // for issue24026
+
+// Test that we don't report a "missing return statement" error
+// (due to incorrect context when type-checking interfaces).
+func issue24140(x interface{}) int {
+ switch x.(type) {
+ case interface{}:
+ return 0
+ default:
+ panic(0)
+ }
+}
// collect embedded interfaces
// Only needed for printing and API. Delay collection
- // to end of type-checking when all types are complete.
+ // to end of type-checking (for package-global interfaces)
+ // when all types are complete. Local interfaces are handled
+ // after each statement (as each statement processes delayed
+ // functions).
interfaceContext := check.context // capture for use in closure below
check.later(func() {
- check.context = interfaceContext
if trace {
check.trace(iface.Pos(), "-- delayed checking embedded interfaces of %s", iface)
check.indent++
check.indent--
}()
}
+
+ // The context must be restored since for local interfaces
+ // delayed functions are processed after each statement
+ // (was issue #24140).
+ defer func(ctxt context) {
+ check.context = ctxt
+ }(check.context)
+ check.context = interfaceContext
+
for _, f := range iface.Methods.List {
if len(f.Names) == 0 {
typ := check.typ(f.Type)