Skip to content

Commit 2953cd0

Browse files
committed
go/internal/gcimporter: prevent importReader reading type parameter twice
This is port of CL 349009 to go/internal/gcimporter. Updates #48280 Change-Id: I7d40d8b67333538ca58fe012535d54e891d0ed16 Reviewed-on: https://go-review.googlesource.com/c/go/+/349010 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent b8c802b commit 2953cd0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/go/internal/gcimporter/iimport.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ type importReader struct {
284284
prevColumn int64
285285
}
286286

287+
// obj reads import declaration for an object. It may not read
288+
// the entire declaration, e.g, for recursive type.
287289
func (r *importReader) obj(name string) {
288290
tag := r.byte()
289291
pos := r.pos()
@@ -309,16 +311,17 @@ func (r *importReader) obj(name string) {
309311
r.declare(types.NewFunc(pos, r.currPkg, name, sig))
310312

311313
case 'T', 'U':
312-
var tparams []*types.TypeParam
313-
if tag == 'U' {
314-
tparams = r.tparamList()
315-
}
316314
// Types can be recursive. We need to setup a stub
317315
// declaration before recursing.
318316
obj := types.NewTypeName(pos, r.currPkg, name, nil)
319317
named := types.NewNamed(obj, nil, nil)
320-
named.SetTypeParams(tparams)
318+
// Declare obj before calling r.tparamList, so the new type name is recognized
319+
// if used in the constraint of one of its own typeparams (see #48280).
321320
r.declare(obj)
321+
if tag == 'U' {
322+
tparams := r.tparamList()
323+
named.SetTypeParams(tparams)
324+
}
322325

323326
underlying := r.p.typAt(r.uint64(), named).Underlying()
324327
named.SetUnderlying(underlying)

0 commit comments

Comments
 (0)