]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: make Interface.obj a *TypeName
authorRobert Griesemer <gri@golang.org>
Wed, 30 Jun 2021 18:21:32 +0000 (11:21 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 1 Jul 2021 16:43:07 +0000 (16:43 +0000)
We know the exact type, so make it that. This saves some code
and a word of space with each Interface.

Follow-up on a comment in https://golang.org/cl/329309.

Change-Id: I827e39d17aae159a52ac563544c5e6d017bc05ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/332011
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/sizeof_test.go
src/cmd/compile/internal/types2/type.go

index 34dafce8bf7a2b957b22d0dee3b7d01c029e5c7f..3377270ef809ffc592c95e745bcb32594e54c4ca 100644 (file)
@@ -479,11 +479,10 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr) {
                        var why string
                        if tpar := asTypeParam(x.typ); tpar != nil {
                                // Type parameter bounds don't specify fields, so don't mention "field".
-                               switch obj := tpar.Bound().obj.(type) {
-                               case nil:
+                               if tname := tpar.Bound().obj; tname != nil {
+                                       why = check.sprintf("interface %s has no method %s", tname.name, sel)
+                               } else {
                                        why = check.sprintf("type bound for %s has no method %s", x.typ, sel)
-                               case *TypeName:
-                                       why = check.sprintf("interface %s has no method %s", obj.name, sel)
                                }
                        } else {
                                why = check.sprintf("type %s has no field or method %s", x.typ, sel)
index 82e1221b67ed721db7d12732e4660ae086f67d3f..0b1f7dacad38f4d2337ade421dbe4c0dd0dcd75d 100644 (file)
@@ -28,7 +28,7 @@ func TestSizeof(t *testing.T) {
                {Tuple{}, 12, 24},
                {Signature{}, 44, 88},
                {Union{}, 24, 48},
-               {Interface{}, 44, 88},
+               {Interface{}, 40, 80},
                {Map{}, 16, 32},
                {Chan{}, 12, 24},
                {Named{}, 84, 160},
index 05e6d77d2248b7a17e333e6968af5e19f1654e05..f8aa453d5ca553f10e346ba729f241a567fabe7b 100644 (file)
@@ -264,7 +264,7 @@ func (s *Signature) Variadic() bool { return s.variadic }
 
 // An Interface represents an interface type.
 type Interface struct {
-       obj       Object        // type name object defining this interface; or nil (for better error messages)
+       obj       *TypeName     // corresponding declared object; or nil (for better error messages)
        methods   []*Func       // ordered list of explicitly declared methods
        embeddeds []Type        // ordered list of explicitly embedded elements
        embedPos  *[]syntax.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space