]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't create or instantiate methods on shape types
authorDan Scales <danscales@google.com>
Mon, 20 Sep 2021 22:34:09 +0000 (15:34 -0700)
committerDan Scales <danscales@google.com>
Tue, 21 Sep 2021 20:39:31 +0000 (20:39 +0000)
We should never use or need methods on non-interface shape types. We do
have corresponding functions instantiated with the appropriate
shape types that take the dictionary and the shape-based receiver as the
first two arguments. Each such function has the same name as what the
corresponding method would be, so it's best not to create the methods
(which would create confusion for import/export). This fixes issue
48414, which happened because of the confusion between these two
functions/methods.

Fixes #48414

Change-Id: I401fbdad791bdb5792617449cad68aa8df1d9911
Reviewed-on: https://go-review.googlesource.com/c/go/+/351114
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/typecheck/iimport.go

index 6dbe3cb455c7d56360ba5d6695bace0de843ee26..44919c2a4b856167551b0a653fcffb1ba306aba6 100644 (file)
@@ -356,6 +356,13 @@ func methods(t *types.Type) []*typeSig {
 
 // imethods returns the methods of the interface type t, sorted by name.
 func imethods(t *types.Type) []*typeSig {
+       if t.HasShape() && !t.IsInterface() {
+               // Non-interface shape types have no methods. (There are
+               // corresponding functions (created by getInstantiation) that take
+               // the dictionary and the receiver of shape type as the first two
+               // arguments.)
+               return nil
+       }
        var methods []*typeSig
        for _, f := range t.AllMethods().Slice() {
                if f.Type.Kind() != types.TFUNC || f.Sym == nil {
index ec4057a8d0c38b593fa806c63d9ef384a39d32c6..57f0dd856611a7af2d1c0cb34e0652c7202a1db4 100644 (file)
@@ -1867,6 +1867,11 @@ func substInstType(t *types.Type, baseType *types.Type, targs []*types.Type) {
        }
        t.SetUnderlying(subst.Typ(baseType.Underlying()))
 
+       if t.HasShape() && !t.IsInterface() {
+               // Concrete shape types have no methods.
+               return
+       }
+
        newfields := make([]*types.Field, baseType.Methods().Len())
        for i, f := range baseType.Methods().Slice() {
                if !f.IsMethod() || types.IsInterfaceMethod(f.Type) {
@@ -1903,8 +1908,9 @@ func substInstType(t *types.Type, baseType *types.Type, targs []*types.Type) {
                newfields[i].Nname = nname
        }
        t.Methods().Set(newfields)
-       if !t.HasTParam() && t.Kind() != types.TINTER && t.Methods().Len() > 0 {
-               // Generate all the methods for a new fully-instantiated type.
+       if !t.HasTParam() && !t.HasShape() && t.Kind() != types.TINTER && t.Methods().Len() > 0 {
+               // Generate all the methods for a new fully-instantiated,
+               // non-interface, non-shape type.
                NeedInstType(t)
        }
 }