]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: remove unneccesary tests in implements and lookup
authorRobert Griesemer <gri@golang.org>
Mon, 15 Nov 2021 04:45:40 +0000 (20:45 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 15 Nov 2021 21:22:18 +0000 (21:22 +0000)
Because the underlying type of a type parameter is an interface,
the questions whether *P for a type parameter P has methods or
not is settled: P is also an interface pointers to interfaces
don't have methods.

This allows us to eliminate the now unneccesary test in "implements"
and also allows us to remove a special case for type parameters in
"lookupFieldOrMethod".

Change-Id: I8b218f81584a8e42e75884089a44293365b700df
Reviewed-on: https://go-review.googlesource.com/c/go/+/363838
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/lookup.go

index a0f6885c51cf93ef4359cd00106044253c80ae6a..13f0661611fb307232331f84ef0b2b78a574945d 100644 (file)
@@ -191,12 +191,6 @@ func (check *Checker) implements(V, T Type, qf Qualifier) error {
        // V must implement T (methods)
        // - check only if we have methods
        if Ti.NumMethods() > 0 {
-               // If the type argument is a pointer to a type parameter, the type argument's
-               // method set is empty.
-               // TODO(gri) is this what we want? (spec question)
-               if base, isPtr := deref(V); isPtr && isTypeParam(base) {
-                       return errorf("%s has no methods", V)
-               }
                if m, wrong := check.missingMethod(V, Ti, true); m != nil {
                        // TODO(gri) needs to print updated name to avoid major confusion in error message!
                        //           (print warning for now)
index b4035e16b3dde560d8aa70c8a56a4d4cd91cf681..4f50ea54b14140ee743b04a4142cb595f8c18c18 100644 (file)
@@ -80,12 +80,8 @@ func lookupFieldOrMethod(T Type, addressable, checkFold bool, pkg *Package, name
 
        typ, isPtr := deref(T)
 
-       // *typ where typ is an interface or type parameter has no methods.
+       // *typ where typ is an interface has no methods.
        if isPtr {
-               // don't look at under(typ) here - was bug (issue #47747)
-               if _, ok := typ.(*TypeParam); ok {
-                       return
-               }
                if _, ok := under(typ).(*Interface); ok {
                        return
                }