]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: remove code for implicit type arguments
authorRobert Griesemer <gri@golang.org>
Thu, 17 Dec 2020 01:16:23 +0000 (17:16 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 17 Dec 2020 16:44:58 +0000 (16:44 +0000)
The design draft doesn't support this anymore.

Also: Fixed a potential bug in the receiver unpack code
      (found by rfindley@).

Change-Id: Ic52eedc686adcb4d5a98884ad0134679c3685c13
Reviewed-on: https://go-review.googlesource.com/c/go/+/278853
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/decl.go
src/cmd/compile/internal/types2/resolver.go

index de6f4df73ee5934dd9bb597580033482aa398a0a..0b7956f28783cb6cccf5a3acee7f5355e0207d85 100644 (file)
@@ -686,33 +686,24 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) (tparams []*TypeNa
        var bound Type
        for i, j := 0, 0; i < len(list); i = j {
                f := list[i]
-               ftype := f.Type
 
                // determine the range of type parameters list[i:j] with identical type bound
                // (declared as in (type a, b, c B))
                j = i + 1
-               for j < len(list) && list[j].Type == ftype {
+               for j < len(list) && list[j].Type == f.Type {
                        j++
                }
 
                // this should never be the case, but be careful
-               if ftype == nil {
+               if f.Type == nil {
                        continue
                }
 
-               // If the type bound expects exactly one type argument, permit leaving
-               // it away and use the corresponding type parameter as implicit argument.
-               // This allows us to write (type p b(p), q b(q), r b(r)) as (type p, q, r b).
-               // Enabled if enableImplicitTParam is set.
-               const enableImplicitTParam = false
-
                // The predeclared identifier "any" is visible only as a constraint
                // in a type parameter list. Look for it before general constraint
                // resolution.
                if tident, _ := f.Type.(*syntax.Name); tident != nil && tident.Value == "any" && check.lookup("any") == nil {
                        bound = universeAny
-               } else if enableImplicitTParam {
-                       bound = check.anyType(f.Type)
                } else {
                        bound = check.typ(f.Type)
                }
@@ -723,34 +714,6 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) (tparams []*TypeNa
                //           type C(type T C) interface {}
                //           (issue #39724).
                if _, ok := bound.Under().(*Interface); ok {
-                       if enableImplicitTParam && isGeneric(bound) {
-                               base := bound.(*Named) // only a *Named type can be generic
-                               if j-i != 1 || len(base.tparams) != 1 {
-                                       // TODO(gri) make this error message better
-                                       check.errorf(ftype, "cannot use generic type %s without instantiation (more than one type parameter)", bound)
-                                       bound = Typ[Invalid]
-                                       continue
-                               }
-                               // We have exactly one type parameter.
-                               // "Manually" instantiate the bound with each type
-                               // parameter the bound applies to.
-                               // TODO(gri) this code (in more general form) is also in
-                               // checker.typInternal for the *ast.CallExpr case. Factor?
-                               typ := new(instance)
-                               typ.check = check
-                               typ.pos = ftype.Pos()
-                               typ.base = base
-                               typ.targs = []Type{tparams[i].typ}
-                               typ.poslist = []syntax.Pos{f.Name.Pos()}
-                               // Make sure we check instantiation works at least once
-                               // and that the resulting type is valid.
-                               check.atEnd(func() {
-                                       check.validType(typ.expand(), nil)
-                               })
-                               // update bound and recorded type
-                               bound = typ
-                               check.recordTypeAndValue(ftype, typexpr, typ, nil)
-                       }
                        // set the type bounds
                        for i < j {
                                tparams[i].typ.(*TypeParam).bound = bound
index 6765c219956078590f85ae07d11cc8daab5cffa0..2c98ca20e30bd7eb37a3ebcd05c31023f90c64c0 100644 (file)
@@ -495,11 +495,13 @@ L: // unpack receiver type
                case *syntax.ParenExpr:
                        rtyp = t.X
                // case *ast.StarExpr:
+               //      ptr = true
                //      rtyp = t.X
                case *syntax.Operation:
                        if t.Op != syntax.Mul || t.Y != nil {
                                break
                        }
+                       ptr = true
                        rtyp = t.X
                default:
                        break L