]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: use TypeList in the Inferred struct
authorRobert Findley <rfindley@google.com>
Fri, 20 Aug 2021 14:19:12 +0000 (10:19 -0400)
committerRobert Findley <rfindley@google.com>
Mon, 23 Aug 2021 13:09:18 +0000 (13:09 +0000)
This is for consistency with how we report TArgs elsewhere, and in case
we ever want to share an internal slice with inference reporting.

Change-Id: Ia8b705a155f4f82bd8da8dc2457289810f875f5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/343934
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/api.go
src/go/types/api_test.go
src/go/types/check.go

index b8e772ada06377c45e5042f8b634cfc3206b55f3..5beeff530c002f9cfa2566ba672f36d7fc7dc055 100644 (file)
@@ -363,7 +363,7 @@ func (tv TypeAndValue) HasOk() bool {
 // Inferred reports the Inferred type arguments and signature
 // for a parameterized function call that uses type inference.
 type Inferred struct {
-       TArgs []Type
+       TArgs *TypeList
        Sig   *Signature
 }
 
index 7a0419bfd54de558e1dbf759af72992309169035..1e7d6f2cfafe5c13336445581c1bea55f9acda43 100644 (file)
@@ -482,7 +482,7 @@ func TestInferredInfo(t *testing.T) {
                }
 
                // look for inferred type arguments and signature
-               var targs []Type
+               var targs *TypeList
                var sig *Signature
                for call, inf := range info.Inferred {
                        var fun ast.Expr
@@ -506,11 +506,12 @@ func TestInferredInfo(t *testing.T) {
                }
 
                // check that type arguments are correct
-               if len(targs) != len(test.targs) {
-                       t.Errorf("package %s: got %d type arguments; want %d", name, len(targs), len(test.targs))
+               if targs.Len() != len(test.targs) {
+                       t.Errorf("package %s: got %d type arguments; want %d", name, targs.Len(), len(test.targs))
                        continue
                }
-               for i, targ := range targs {
+               for i := 0; i < targs.Len(); i++ {
+                       targ := targs.At(i)
                        if got := targ.String(); got != test.targs[i] {
                                t.Errorf("package %s, %d. type argument: got %s; want %s", name, i, got, test.targs[i])
                                continue
index b2d076dc680fc7456e8aff21c62d4c3ba01c6287..909bf8d52d07182d43d823f5bddd57ef70497a5e 100644 (file)
@@ -406,8 +406,8 @@ func (check *Checker) recordCommaOkTypes(x ast.Expr, a [2]Type) {
 func (check *Checker) recordInferred(call ast.Expr, targs []Type, sig *Signature) {
        assert(call != nil)
        assert(sig != nil)
-       if m := check.Info.Inferred; m != nil {
-               m[call] = Inferred{targs, sig}
+       if m := check.Inferred; m != nil {
+               m[call] = Inferred{&TypeList{targs}, sig}
        }
 }