@@ -6,7 +6,6 @@ package types2
66
77import (
88 "cmd/compile/internal/syntax"
9- "fmt"
109 . "internal/types/errors"
1110 "sort"
1211 "strings"
@@ -212,7 +211,6 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
212211 // we can get rid of the mpos map below and simply use the cloned method's
213212 // position.
214213
215- var todo []* Func
216214 var seen objset
217215 var allMethods []* Func
218216 mpos := make (map [* Func ]syntax.Pos ) // method specification or method embedding position, for good error messages
@@ -222,36 +220,30 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
222220 allMethods = append (allMethods , m )
223221 mpos [m ] = pos
224222 case explicit :
225- if check == nil {
226- panic (fmt .Sprintf ("%s: duplicate method %s" , m .pos , m .name ))
223+ if check != nil {
224+ var err error_
225+ err .code = DuplicateDecl
226+ err .errorf (pos , "duplicate method %s" , m .name )
227+ err .errorf (mpos [other .(* Func )], "other declaration of %s" , m .name )
228+ check .report (& err )
227229 }
228- // check != nil
229- var err error_
230- err .code = DuplicateDecl
231- err .errorf (pos , "duplicate method %s" , m .name )
232- err .errorf (mpos [other .(* Func )], "other declaration of %s" , m .name )
233- check .report (& err )
234230 default :
235231 // We have a duplicate method name in an embedded (not explicitly declared) method.
236232 // Check method signatures after all types are computed (go.dev/issue/33656).
237233 // If we're pre-go1.14 (overlapping embeddings are not permitted), report that
238234 // error here as well (even though we could do it eagerly) because it's the same
239235 // error message.
240- if check == nil {
241- // check method signatures after all locally embedded interfaces are computed
242- todo = append (todo , m , other .(* Func ))
243- break
236+ if check != nil {
237+ check .later (func () {
238+ if ! check .allowVersion (m .pkg , pos , go1_14 ) || ! Identical (m .typ , other .Type ()) {
239+ var err error_
240+ err .code = DuplicateDecl
241+ err .errorf (pos , "duplicate method %s" , m .name )
242+ err .errorf (mpos [other .(* Func )], "other declaration of %s" , m .name )
243+ check .report (& err )
244+ }
245+ }).describef (pos , "duplicate method check for %s" , m .name )
244246 }
245- // check != nil
246- check .later (func () {
247- if ! check .allowVersion (m .pkg , pos , go1_14 ) || ! Identical (m .typ , other .Type ()) {
248- var err error_
249- err .code = DuplicateDecl
250- err .errorf (pos , "duplicate method %s" , m .name )
251- err .errorf (mpos [other .(* Func )], "other declaration of %s" , m .name )
252- check .report (& err )
253- }
254- }).describef (pos , "duplicate method check for %s" , m .name )
255247 }
256248 }
257249
@@ -314,15 +306,6 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
314306 }
315307 ityp .embedPos = nil // not needed anymore (errors have been reported)
316308
317- // process todo's (this only happens if check == nil)
318- for i := 0 ; i < len (todo ); i += 2 {
319- m := todo [i ]
320- other := todo [i + 1 ]
321- if ! Identical (m .typ , other .typ ) {
322- panic (fmt .Sprintf ("%s: duplicate method %s" , m .pos , m .name ))
323- }
324- }
325-
326309 ityp .tset .comparable = allComparable
327310 if len (allMethods ) != 0 {
328311 sortMethods (allMethods )
0 commit comments