diff options
-rw-r--r-- | src/go/internal/gcimporter/iimport.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/go/internal/gcimporter/iimport.go b/src/go/internal/gcimporter/iimport.go index 039fc6a61b..56f6418d5e 100644 --- a/src/go/internal/gcimporter/iimport.go +++ b/src/go/internal/gcimporter/iimport.go @@ -284,6 +284,8 @@ type importReader struct { prevColumn int64 } +// obj reads import declaration for an object. It may not read +// the entire declaration, e.g, for recursive type. func (r *importReader) obj(name string) { tag := r.byte() pos := r.pos() @@ -309,16 +311,17 @@ func (r *importReader) obj(name string) { r.declare(types.NewFunc(pos, r.currPkg, name, sig)) case 'T', 'U': - var tparams []*types.TypeParam - if tag == 'U' { - tparams = r.tparamList() - } // Types can be recursive. We need to setup a stub // declaration before recursing. obj := types.NewTypeName(pos, r.currPkg, name, nil) named := types.NewNamed(obj, nil, nil) - named.SetTypeParams(tparams) + // Declare obj before calling r.tparamList, so the new type name is recognized + // if used in the constraint of one of its own typeparams (see #48280). r.declare(obj) + if tag == 'U' { + tparams := r.tparamList() + named.SetTypeParams(tparams) + } underlying := r.p.typAt(r.uint64(), named).Underlying() named.SetUnderlying(underlying) |