]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: use type variables consistently in Checker.conversion
authorRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 03:22:26 +0000 (22:22 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 14:02:36 +0000 (14:02 +0000)
This is a clean port of CL 362895 from types2 to go/types.

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

index 26bebd4adebb82f09676eb16982c5ec31f0b6cd4..18d24e404c832ce1d83abfa557d33ac0f136d1a6 100644 (file)
@@ -139,39 +139,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 is a slice, T is a pointer-to-array type,
+       // "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) {
@@ -249,20 +249,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
 }