Skip to content

Commit 3883e4a

Browse files
committed
go/internal/gcimporter: allow both prefixes and subscripts for tparams
Add some flexibility to the gcimporter while we work on adjusting the compiler to identify type parameters with a path prefix, rather than a numeric subscript. Change-Id: Ia9d5b0d3daebf31b9181dce5127da637d40510ba Reviewed-on: https://go-review.googlesource.com/c/tools/+/353410 Trust: Robert Findley <[email protected]> Trust: Dan Scales <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dan Scales <[email protected]>
1 parent 6f5fd9b commit 3883e4a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

go/internal/gcimporter/iimport.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"go/types"
1919
"io"
2020
"sort"
21+
"strings"
2122

2223
"golang.org/x/tools/internal/typeparams"
2324
)
@@ -405,12 +406,21 @@ func (r *importReader) obj(name string) {
405406
if r.p.exportVersion < iexportVersionGenerics {
406407
errorf("unexpected type param type")
407408
}
408-
name0, sub := parseSubscript(name)
409+
// Temporarily strip both type parameter subscripts and path prefixes,
410+
// while we replace subscripts with prefixes in the compiler.
411+
// TODO(rfindley): remove support for subscripts once the compiler changes
412+
// have landed.
413+
name0, _ := parseSubscript(name)
414+
ix := strings.LastIndex(name, ".")
415+
name0 = name0[ix+1:]
409416
tn := types.NewTypeName(pos, r.currPkg, name0, nil)
410417
t := typeparams.NewTypeParam(tn, nil)
411-
if sub == 0 {
412-
errorf("name %q missing subscript", name)
413-
}
418+
419+
// The check below is disabled so that we can support both path-prefixed
420+
// and subscripted type parameter names.
421+
// if sub == 0 {
422+
// errorf("name %q missing subscript", name)
423+
// }
414424

415425
// TODO(rfindley): can we use a different, stable ID?
416426
// t.SetId(sub)

0 commit comments

Comments
 (0)