}
case *Named:
+ // don't report a 2nd error if we already know the type is invalid
+ // (e.g., if a cycle was detected earlier, via Checker.underlying).
+ if t.underlying == Typ[Invalid] {
+ t.info = invalid
+ return invalid
+ }
switch t.info {
case unknown:
t.info = marked
- t.info = check.validType(t.underlying, append(path, t.obj))
+ t.info = check.validType(t.orig, append(path, t.obj))
case marked:
// cycle detected
for i, tn := range path {
obj.typ = named // make sure recursive type declarations terminate
// determine underlying type of named
- check.definedType(typ, named)
+ named.orig = check.definedType(typ, named)
// The underlying type of named may be itself a named type that is
// incomplete:
A0 /* ERROR cycle */ [10]A0
A1 [10]*A1
- // TODO(gri) It would be nicer to report the cycle starting
- // with A2 (also below, for S4). See issue #34771.
- A2 [10]A3
- A3 /* ERROR cycle */ [10]A4
+ A2 /* ERROR cycle */ [10]A3
+ A3 [10]A4
A4 A2
A5 [10]A6
S2 struct{ _ *S2 }
S3 struct{ *S3 }
- S4 struct{ S5 }
- S5 /* ERROR cycle */ struct{ S6 }
+ S4 /* ERROR cycle */ struct{ S5 }
+ S5 struct{ S6 }
S6 S4
// pointers
C0 chan C0
)
+// test case for issue #34771
+type (
+ AA /* ERROR cycle */ B
+ B C
+ C [10]D
+ D E
+ E AA
+)
+
func _() {
type (
t1 /* ERROR cycle */ t1
type Named struct {
info typeInfo // for cycle detection
obj *TypeName // corresponding declared object
+ orig Type // type (on RHS of declaration) this *Named type is derived of (for cycle reporting)
underlying Type // possibly a *Named during setup; never a *Named once set up completely
methods []*Func // methods declared for this type (not the method set of this type); signatures are type-checked lazily
}
if _, ok := underlying.(*Named); ok {
panic("types.NewNamed: underlying type must not be *Named")
}
- typ := &Named{obj: obj, underlying: underlying, methods: methods}
+ typ := &Named{obj: obj, orig: underlying, underlying: underlying, methods: methods}
if obj.typ == nil {
obj.typ = typ
}