]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: remove disabled code related to type...
authorRobert Griesemer <gri@golang.org>
Tue, 5 Jan 2021 20:33:11 +0000 (12:33 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 6 Jan 2021 16:46:01 +0000 (16:46 +0000)
Earlier (contract-based) versions of the generics design restricted the
kind of types that could be used in a type list - the current design does
not have these restrictions anymore. Remove the respective checking code.

Change-Id: Ia333f7aa8a9c31a92c08acbd5cadba3532a455b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/281546
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/typexpr.go

index 3ee8ac85cfb860649dbfb7d7a7c927d4068bef51..910db0819f75eb152dc9aced11528dbca8fb3aa9 100644 (file)
@@ -1192,18 +1192,7 @@ func (check *Checker) collectTypeConstraints(pos syntax.Pos, types []syntax.Expr
                        check.invalidASTf(pos, "missing type constraint")
                        continue
                }
-               typ := check.varType(texpr)
-               // A type constraint may be a predeclared type or a
-               // composite type composed of only predeclared types.
-               // TODO(gri) If we enable this again it also must run
-               // at the end.
-               const restricted = false
-               var why string
-               if restricted && !check.typeConstraint(typ, &why) {
-                       check.errorf(texpr, "invalid type constraint %s (%s)", typ, why)
-                       continue
-               }
-               list = append(list, typ)
+               list = append(list, check.varType(texpr))
        }
 
        // Ensure that each type is only present once in the type list.  Types may be
@@ -1234,62 +1223,6 @@ func includes(list []Type, typ Type) bool {
        return false
 }
 
-// typeConstraint checks that typ may be used in a type list.
-// For now this just checks for the absence of defined (*Named) types.
-func (check *Checker) typeConstraint(typ Type, why *string) bool {
-       switch t := typ.(type) {
-       case *Basic:
-               // ok
-       case *Array:
-               return check.typeConstraint(t.elem, why)
-       case *Slice:
-               return check.typeConstraint(t.elem, why)
-       case *Struct:
-               for _, f := range t.fields {
-                       if !check.typeConstraint(f.typ, why) {
-                               return false
-                       }
-               }
-       case *Pointer:
-               return check.typeConstraint(t.base, why)
-       case *Tuple:
-               if t == nil {
-                       return true
-               }
-               for _, v := range t.vars {
-                       if !check.typeConstraint(v.typ, why) {
-                               return false
-                       }
-               }
-       case *Signature:
-               if len(t.tparams) != 0 {
-                       panic("type parameter in function type")
-               }
-               return (t.recv == nil || check.typeConstraint(t.recv.typ, why)) &&
-                       check.typeConstraint(t.params, why) &&
-                       check.typeConstraint(t.results, why)
-       case *Interface:
-               t.assertCompleteness()
-               for _, m := range t.allMethods {
-                       if !check.typeConstraint(m.typ, why) {
-                               return false
-                       }
-               }
-       case *Map:
-               return check.typeConstraint(t.key, why) && check.typeConstraint(t.elem, why)
-       case *Chan:
-               return check.typeConstraint(t.elem, why)
-       case *Named:
-               *why = check.sprintf("contains defined type %s", t)
-               return false
-       case *TypeParam:
-               // ok, e.g.: func f (type T interface { type T }) ()
-       default:
-               unreachable()
-       }
-       return true
-}
-
 func ptrBase(x *syntax.Operation) syntax.Expr {
        if x.Op == syntax.Mul && x.Y == nil {
                return x.X