@@ -629,27 +629,33 @@ func (check *Checker) packageObjects() {
629
629
}
630
630
}
631
631
632
- // We process non-alias declarations first, in order to avoid situations where
633
- // the type of an alias declaration is needed before it is available. In general
634
- // this is still not enough, as it is possible to create sufficiently convoluted
635
- // recursive type definitions that will cause a type alias to be needed before it
636
- // is available (see issue #25838 for examples).
637
- // As an aside, the cmd/compiler suffers from the same problem (#25838).
632
+ // We process non-alias type declarations first, followed by alias declarations,
633
+ // and then everything else. This appears to avoid most situations where the type
634
+ // of an alias is needed before it is available.
635
+ // There may still be cases where this is not good enough (see also issue #25838).
636
+ // In those cases Checker.ident will report an error ("invalid use of type alias").
638
637
var aliasList []* TypeName
639
- // phase 1
638
+ var othersList []Object // everything that's not a type
639
+ // phase 1: non-alias type declarations
640
640
for _ , obj := range objList {
641
- // If we have a type alias, collect it for the 2nd phase.
642
- if tname , _ := obj .(* TypeName ); tname != nil && check .objMap [tname ].tdecl .Assign .IsValid () {
643
- aliasList = append (aliasList , tname )
644
- continue
641
+ if tname , _ := obj .(* TypeName ); tname != nil {
642
+ if check .objMap [tname ].tdecl .Assign .IsValid () {
643
+ aliasList = append (aliasList , tname )
644
+ } else {
645
+ check .objDecl (obj , nil )
646
+ }
647
+ } else {
648
+ othersList = append (othersList , obj )
645
649
}
646
-
647
- check .objDecl (obj , nil )
648
650
}
649
- // phase 2
651
+ // phase 2: alias type declarations
650
652
for _ , obj := range aliasList {
651
653
check .objDecl (obj , nil )
652
654
}
655
+ // phase 3: all other declarations
656
+ for _ , obj := range othersList {
657
+ check .objDecl (obj , nil )
658
+ }
653
659
654
660
// At this point we may have a non-empty check.methods map; this means that not all
655
661
// entries were deleted at the end of typeDecl because the respective receiver base
0 commit comments