]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: move match function to end of file (cleanup)
authorRobert Findley <rfindley@google.com>
Thu, 18 Nov 2021 00:29:13 +0000 (19:29 -0500)
committerRobert Findley <rfindley@google.com>
Thu, 18 Nov 2021 02:17:34 +0000 (02:17 +0000)
This is a port of CL 363669 from types2 to go/types.

Change-Id: Id1f375ff5708dab528144e30ce16d24d6fdf7d00
Reviewed-on: https://go-review.googlesource.com/c/go/+/364900
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/type.go

index 099449c8b9c8ff9baba2598880fe59de80c72d26..3acb19c41240fcf5713c72f81c50b1b467026d03 100644 (file)
@@ -27,35 +27,6 @@ func under(t Type) Type {
        return t.Underlying()
 }
 
-// If x and y are identical, match returns x.
-// If x and y are identical channels but for their direction
-// and one of them is unrestricted, match returns the channel
-// with the restricted direction.
-// In all other cases, match returns nil.
-func match(x, y Type) Type {
-       // Common case: we don't have channels.
-       if Identical(x, y) {
-               return x
-       }
-
-       // We may have channels that differ in direction only.
-       if x, _ := x.(*Chan); x != nil {
-               if y, _ := y.(*Chan); y != nil && Identical(x.elem, y.elem) {
-                       // We have channels that differ in direction only.
-                       // If there's an unrestricted channel, select the restricted one.
-                       switch {
-                       case x.dir == SendRecv:
-                               return y
-                       case y.dir == SendRecv:
-                               return x
-                       }
-               }
-       }
-
-       // types are different
-       return nil
-}
-
 // If t is not a type parameter, structuralType returns the underlying type.
 // If t is a type parameter, structuralType returns the single underlying
 // type of all types in its type set if it exists, or nil otherwise. If the
@@ -124,3 +95,32 @@ func structuralString(t Type) Type {
        }
        return nil
 }
+
+// If x and y are identical, match returns x.
+// If x and y are identical channels but for their direction
+// and one of them is unrestricted, match returns the channel
+// with the restricted direction.
+// In all other cases, match returns nil.
+func match(x, y Type) Type {
+       // Common case: we don't have channels.
+       if Identical(x, y) {
+               return x
+       }
+
+       // We may have channels that differ in direction only.
+       if x, _ := x.(*Chan); x != nil {
+               if y, _ := y.(*Chan); y != nil && Identical(x.elem, y.elem) {
+                       // We have channels that differ in direction only.
+                       // If there's an unrestricted channel, select the restricted one.
+                       switch {
+                       case x.dir == SendRecv:
+                               return y
+                       case y.dir == SendRecv:
+                               return x
+                       }
+               }
+       }
+
+       // types are different
+       return nil
+}