Skip to content

Commit 5ba0649

Browse files
committed
[dev.typeparams] go/types: use the TParams API consistently
Even internally to the type checker, we should use the TParams and RParams methods instead of accessing fields directly, as TParams may be lazily expanded, and in the future we may want to pack receiver and function type parameters into a single field on Signature. We should also not differentiate a nil *TParamList from an empty *TParamList. Change-Id: I85c616e6c708a89b6a5eb1e69fe0b014276eda90 Reviewed-on: https://go-review.googlesource.com/c/go/+/336251 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 6f57139 commit 5ba0649

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/go/types/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (check *Checker) funcInst(x *operand, ix *typeparams.IndexExpr) {
6161

6262
// instantiate function signature
6363
res := check.Instantiate(x.Pos(), sig, targs, poslist, true).(*Signature)
64-
assert(res.tparams == nil) // signature is not generic anymore
64+
assert(res.TParams().Len() == 0) // signature is not generic anymore
6565
if inferred {
6666
check.recordInferred(ix.Orig, targs, res)
6767
}
@@ -334,7 +334,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
334334

335335
// compute result signature
336336
rsig = check.Instantiate(call.Pos(), sig, targs, nil, true).(*Signature)
337-
assert(rsig.tparams == nil) // signature is not generic anymore
337+
assert(rsig.TParams().Len() == 0) // signature is not generic anymore
338338
check.recordInferred(call, targs, rsig)
339339

340340
// Optimization: Only if the parameter list was adjusted do we

src/go/types/decl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
625625
named.underlying = under(named)
626626

627627
// If the RHS is a type parameter, it must be from this type declaration.
628-
if tpar, _ := named.underlying.(*TypeParam); tpar != nil && tparamIndex(named.tparams.list(), tpar) < 0 {
628+
if tpar, _ := named.underlying.(*TypeParam); tpar != nil && tparamIndex(named.TParams().list(), tpar) < 0 {
629629
check.errorf(tdecl.Type, _Todo, "cannot use function type parameter %s as RHS in type declaration", tpar)
630630
named.underlying = Typ[Invalid]
631631
}

src/go/types/subst.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (subst *subster) typ(typ Type) Type {
193193
}
194194
}
195195

196-
if t.TParams() == nil {
196+
if t.TParams().Len() == 0 {
197197
dump(">>> %s is not parameterized", t)
198198
return t // type is not parameterized
199199
}

src/go/types/typestring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
276276
buf.WriteByte('[')
277277
writeTypeList(buf, t.targs, qf, visited)
278278
buf.WriteByte(']')
279-
} else if t.TParams() != nil {
279+
} else if t.TParams().Len() != 0 {
280280
// parameterized type
281281
writeTParamList(buf, t.TParams().list(), qf, visited)
282282
}
@@ -424,7 +424,7 @@ func WriteSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier) {
424424
}
425425

426426
func writeSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier, visited []Type) {
427-
if sig.tparams != nil {
427+
if sig.TParams().Len() != 0 {
428428
writeTParamList(buf, sig.TParams().list(), qf, visited)
429429
}
430430

0 commit comments

Comments
 (0)