]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: use type variables consistently in Checker.conversion
authorRobert Griesemer <gri@golang.org>
Wed, 10 Nov 2021 05:12:03 +0000 (21:12 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 10 Nov 2021 17:15:52 +0000 (17:15 +0000)
We have V and T and Vu and Tu. When calling the various isX predicates
consistently use Vu and Tu.

(We could also use V an T because the predicates call under anyway,
but using Vu and Tu removes an unnecessary call to Named.under if
V or T are *Named.)

Also, removed some outdated comments.

Change-Id: I6fcd9ce5f6292e89ac2afd597b72fd0790e84ff1
Reviewed-on: https://go-review.googlesource.com/c/go/+/362895
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/conversions.go

index dd89f297623f1dbb30a7bed757661cbefb9c7d3d..7f93e2467f68d2d40f0fac3b7c878b5c2f8ef9f7 100644 (file)
@@ -142,39 +142,39 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
        }
 
        // "V and T are both integer or floating point types"
-       if isIntegerOrFloat(V) && isIntegerOrFloat(T) {
+       if isIntegerOrFloat(Vu) && isIntegerOrFloat(Tu) {
                return true
        }
 
        // "V and T are both complex types"
-       if isComplex(V) && isComplex(T) {
+       if isComplex(Vu) && isComplex(Tu) {
                return true
        }
 
        // "V is an integer or a slice of bytes or runes and T is a string type"
-       if (isInteger(V) || isBytesOrRunes(Vu)) && isString(T) {
+       if (isInteger(Vu) || isBytesOrRunes(Vu)) && isString(Tu) {
                return true
        }
 
        // "V is a string and T is a slice of bytes or runes"
-       if isString(V) && isBytesOrRunes(Tu) {
+       if isString(Vu) && isBytesOrRunes(Tu) {
                return true
        }
 
        // package unsafe:
        // "any pointer or value of underlying type uintptr can be converted into a unsafe.Pointer"
-       if (isPointer(Vu) || isUintptr(Vu)) && isUnsafePointer(T) {
+       if (isPointer(Vu) || isUintptr(Vu)) && isUnsafePointer(Tu) {
                return true
        }
        // "and vice versa"
-       if isUnsafePointer(V) && (isPointer(Tu) || isUintptr(Tu)) {
+       if isUnsafePointer(Vu) && (isPointer(Tu) || isUintptr(Tu)) {
                return true
        }
 
        // "V a slice, T is a pointer-to-array type,
        // and the slice and array types have identical element types."
-       if s, _ := under(V).(*Slice); s != nil {
-               if p, _ := under(T).(*Pointer); p != nil {
+       if s, _ := Vu.(*Slice); s != nil {
+               if p, _ := Tu.(*Pointer); p != nil {
                        if a, _ := under(p.Elem()).(*Array); a != nil {
                                if Identical(s.Elem(), a.Elem()) {
                                        if check == nil || check.allowVersion(check.pkg, 1, 17) {
@@ -257,20 +257,12 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
        return false
 }
 
-// Helper predicates for convertibleToImpl. The types provided to convertibleToImpl
-// may be type parameters but they won't have specific type terms. Thus it is ok to
-// use the toT convenience converters in the predicates below.
-
 func isUintptr(typ Type) bool {
        t, _ := under(typ).(*Basic)
        return t != nil && t.kind == Uintptr
 }
 
 func isUnsafePointer(typ Type) bool {
-       // TODO(gri): Is this under(typ).(*Basic) instead of typ.(*Basic) correct?
-       //            (The former calls under(), while the latter doesn't.)
-       //            The spec does not say so, but gc claims it is. See also
-       //            issue 6326.
        t, _ := under(typ).(*Basic)
        return t != nil && t.kind == UnsafePointer
 }